-
Notifications
You must be signed in to change notification settings - Fork 0
/
Battery_and_Temp_Warner.sh
executable file
·53 lines (47 loc) · 1.84 KB
/
Battery_and_Temp_Warner.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
export LANG=en_US.UTF-8
###################################################################
#Script Name :Battery and Temp Warner
#Description :This script checks the battery status and CPU temperature and warns the user
# when battery is discharging and percentage is too low and also
# when the CPU temperature is too high.
# The limits can be changed/reset in the code if desired.
# ($number -gt XX for battery and arrayCpuTemp -gt XX for CPU temp)
#Args :
#Author :Johannes Wülk
#Email :[email protected]
###################################################################
battery="acpi | grep -o 'Discharging.*%'"
cpuTemp="sensors | grep -A 0 'CPU' | grep -o '[0-9]\+'"
while true #loop forever
do
outputBattery=$(eval $battery)
outputCpuTemp=$(eval $cpuTemp)
if [[ $outputBattery == *"Discharging"* ]] #check if plugged in
then
#echo "Battery discharging."
#write output into array with space as delimiter
IFS=' ' read -r -a arrayBatt <<< "$outputBattery"
for element in "${arrayBatt[@]}"
do
if [[ $element == *"%"* ]]
then
number=$(echo "$element" | tr -d %)
if [[ $number -lt 30 ]] #check if battery status under 30
then
batteryNotify="Please charge battery now. \nDraining it too low reduces its lifespan."
zenity --no-wrap --warning --text "$batteryNotify" #or old: notify-send
fi
fi
done
fi
IFS=$'\n' read -r -a arrayCpuTemp <<< "$outputCpuTemp"
if [[ arrayCpuTemp -gt 80 ]] #check if cpu temp over 80 °C
then
cpuTempNotify="CPU has reached "
cpuTempNotify+="$arrayCpuTemp"
cpuTempNotify+=" °C, \nplease cool immediately \nor shut down computer."
zenity --no-wrap --warning --text "$cpuTempNotify"
fi
sleep 120 #check every 2 minutes
done