-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_shutdown.sh
More file actions
executable file
·39 lines (34 loc) · 873 Bytes
/
auto_shutdown.sh
File metadata and controls
executable file
·39 lines (34 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# This is a tiny script which shut downs the computer if none of the given
# hosts is online anymore. Customize the HOSTS array to fit your needs.
HOSTS=(
'example'
'foobar'
)
OFFLINE_HOSTS=0
for HOST in ${HOSTS[@]}
do
ping -c 3 $HOST > /dev/null 2>&1
EXITSTATUS=$?
if [[ $EXITSTATUS -eq 1 ]]
then
OFFLINE_HOSTS=$((OFFLINE_HOSTS + 1))
fi
done
if [[ $OFFLINE_HOSTS -eq ${#HOSTS[@]} ]]
then
# check if a RAID array could exist
if [[ -f "/proc/mdstat" ]]
then
# shutdown but check if raid is clean before shutdown
NONOK_RAID_COUNT = $(grep -c "\[.*_.*\]|recovery" /proc/mdstat)
if [[ $NONOK_RAID_COUNT -eq 0 ]]
then
# shutdown, RAID is clean
/sbin/shutdown -h now
fi
else
# shutdown, there is no RAID
/sbin/shutdown -h now
fi
fi