-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.sh
executable file
·39 lines (31 loc) · 1.65 KB
/
temperature.sh
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
# License:
# Copyright (C) 2018 Pavel Dmitriev <[email protected]>
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
# Synopsis:
# The script checks Raspberry PI CPU temperature
# and sends GUI notification to an administrator workstation
# if the temperature is higher than defined $THRESHOLD
# The temperature is present as NN.NNN °C integer without dot
# Requirements:
# 1. ssh login to an administrator workstation without password
# 2. KDE or libnotify-tools / libnotify-bin installed
#Installation:
# 1. Make this script as executable with chmod +x temperature.sh
# 2. Add script to crontab to execute every minute:
# */1 * * * * user /path/to/temperature.sh
THRESHOLD=60000
SSH_USER=user
SSH_HOST=host
KDE=false
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp)
if [ "$TEMP" -gt "$THRESHOLD" ]; then
HTEMP=$(expr $TEMP / 1000)
if [ "$KDE" = "true" ]; then
ssh "$SSH_USER"@"$SSH_HOST" 'DISPLAY=:0 kdialog --passivepopup "Raspberry PI. High temperature! '"$HTEMP"'°C" 3600'
else
ssh "$SSH_USER"@"$SSH_HOST" 'notify-send -u critical -t 3600000 "Raspberry PI" "High temperature! '"$HTEMP"'°C"'
fi
fi