Skip to content

Instantly share code, notes, and snippets.

@delfer
Created May 28, 2018 18:13
Show Gist options
  • Select an option

  • Save delfer/ce738c33d57363b7556d1288ff18ef47 to your computer and use it in GitHub Desktop.

Select an option

Save delfer/ce738c33d57363b7556d1288ff18ef47 to your computer and use it in GitHub Desktop.
Script for cron to monitor RPI's CPU temperature and disk accessibility
#!/bin/bash
API=https://api.telegram.org/botXXX/sendMessage
CHAT=YYYY
function send {
curl -s -X POST $API -d chat_id="$CHAT" -d text="$1"
}
OK_MARK=$(echo -e '\u2705')
BAD_MARK=$(echo -e '\u274C')
TEMP_CUR=$(cat /sys/class/thermal/thermal_zone0/temp)
TEMP_CUR_T=$(echo $TEMP_CUR | awk '{print $1/1000}')
TEMP_MAX="70000"
TEMP_MAX_T=$(echo $TEMP_MAX | awk '{print $1/1000}')
TEST_FILE=/mnt/disk/pi-mon-test
TEMP_LOCK=/var/lock/pi-mon-temp
DISK_LOCK=/var/lock/pi-mon-disk
if [ "$TEMP_CUR" -ge "$TEMP_MAX" ] && [ ! -f $TEMP_LOCK ]
then
send "$BAD_MARK Tempereture $TEMP_CUR_T *C is over $TEMP_MAX_T *C"
touch $TEMP_LOCK
fi
if [ "$TEMP_CUR" -lt "$TEMP_MAX" ] && [ -f $TEMP_LOCK ]
then
send "$OK_MARK Tempereture $TEMP_CUR_T *C is less $TEMP_MAX_T *C"
rm $TEMP_LOCK
fi
touch $TEST_FILE
TEST=$?
if [ "$TEST" -ne "0" ] && [ ! -f $DISK_LOCK ]
then
send "$BAD_MARK Disk lost"
touch $DISK_LOCK
fi
if [ "$TEST" -eq "0" ] && [ -f $DISK_LOCK ]
then
send "$OK_MARK Disk come back"
rm $DISK_LOCK
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment