Debian Codegraph @

prog/daemon/healthd.sh

raw
1 #!/bin/bash
2 #
3 # healthd -- This is a simple daemon which can be used to alert you in the
4 # event of a hardware health monitoring alarm by sending an
5 # email to the value of ADMIN_EMAIL (defined below).
6 #
7 # To Use -- Simply start the daemon from a shell (may be backgrounded)
8 #
9 # Other details -- Checks status every 15 seconds. Sends warning emails every
10 # ten minutes during alarm until the alarm is cleared.
11 # It won't start up if there is a pending alarm on startup.
12 # Very low loading on the machine (sleeps almost all the time).
13 # This is just an example. It works, but hopefully we can
14 # get something better written. :')
15 #
16 # Requirements -- mail, sensors, bash, sleep
17 #
18 # Written & Copyrighten by Philip Edelbrock, 1999.
19 #
20 # Version: 1.1
21 #
22
23 ADMIN_EMAIL="root@localhost"
24
25 # Try loading the built-in sleep implementation to avoid spawning a
26 # new process every 15 seconds
27 enable -f sleep.so sleep >/dev/null 2>&1
28
29 sensors_state=$(sensors)
30 if [[ "$sensors_state" =~ 'ALARM' ]]
31 then
32 echo "Pending Alarms on start up! Exiting!"
33 exit
34 fi
35
36 while true
37 do
38 sleep 15
39 sensors_state=$(sensors)
40 if [[ "$sensors_state" =~ 'ALARM' ]]
41 then
42 echo "$sensors_state" | mail -s '**** Hardware Health Warning ****' $ADMIN_EMAIL
43 sleep 600
44 fi
45 done