diff options
| -rwxr-xr-x | heartbeat.sh | 25 | ||||
| -rwxr-xr-x | reboot.sh | 36 |
2 files changed, 61 insertions, 0 deletions
diff --git a/heartbeat.sh b/heartbeat.sh new file mode 100755 index 0000000..c98e783 --- /dev/null +++ b/heartbeat.sh @@ -0,0 +1,25 @@ +#!/bin/bash - + +# heartbeat.sh +# SJP 9 September 2014 +# +# Monitors uptime and logs it in case of shutdown +# +# Designed to be run frequently from cron + +# Have we just rebooted? Don't want to overwrite! +[ -e ~/mail/monitor/data/heartlock ] && exit 1337 + +# get CPU temperature +cputemp=$(cat /sys/class/thermal/thermal_zone0/temp) +cputemp=$[cputemp/1000] + +cat << EOF > ~/mail/monitor/data/heartbeat.txt + +Heartbeat: $(date) CPU temperature: $cputemp +-------------------------------------- +$(procinfo -Hr) + +EOF + + diff --git a/reboot.sh b/reboot.sh new file mode 100755 index 0000000..19c9391 --- /dev/null +++ b/reboot.sh @@ -0,0 +1,36 @@ +#!/bin/bash - +# SJP 9 Sept 2014 +# Run by cron after reboot. +# Sends an email to st33v. + +# https://www.linuxquestions.org/questions/linux-server-73/delay-startup-script-until-15-minutes-after-boot-661245/ +# at now + 15 minutes -f your_script +# Alternately, use a script, whose first line is +# sleep 900 +# and start it from rc.local like this +# nohup /path/myscript & +# which will disconnect it from the startup and background it. + +cd ~/mail/monitor +touch data/heartlock # make a file to stop heartbeat overwriting + +cat <<- EOF > data/emailbody.txt + Cumquat has rebooted + ==================== + + $(cat data/heartbeat.txt) + + ----------------------------------------------------------- + Current status at $(date): + $(procinfo -Hr) + + ----------------------------------------------------------- + Was there a shutdown command? + $(cat /var/log/auth.log | grep shutdown) + +EOF + +sleep 180 # wait 3 mins to make sure have network +cat data/emailbody.txt | mail -A cumquat -s "Cumquat reboot notification" $EMAILST33V +rm data/emailbody.txt +rm data/heartlock |
