added coretemp.sh to i3block_shell scripts collection

This commit is contained in:
simon 2021-01-24 15:01:23 +07:00
parent fd44a722be
commit 6472c4ea2d
2 changed files with 42 additions and 0 deletions

View File

@ -29,6 +29,7 @@ None standard Python dependencies:
## i3block_shell
A bunch of simple bash scripts to be called via i3blocks.
* **coretemp.sh** Echos average temperature of all CPU cores by parsing output of `sensors` from package *lm_sensors*
* **date.sh**: Echos the current date
* on left click: uses notify-send to print current three month calendar
* **df.sh**: Echos current diskfree level of the root partition

41
i3block_shell/coretemp.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# print temp for i3 blocks
# reads output from sensors command
all_sensors=$(sensors | grep -E "Core [0-9]" | awk '{print $3}' \
| cut -d'.' -f 1 | sed 's/+//g')
# build array
sensors_arr=()
while IFS= read -r line; do
sensors_arr+=("$line")
done <<< "$all_sensors"
# calc average
cores="${#sensors_arr[@]}"
sum_cores=$(IFS=+; echo "$((${sensors_arr[*]}))")
temp=$(( sum_cores / cores ))
# split based on temp
if [[ $temp -le 60 ]]; then
printmain="$temp°C"
printsmall=""
printcolor=""
elif [[ $temp -gt 60 ]] && [[ $temp -lt 75 ]]; then
printmain="$temp°C"
printsmall=""
printcolor="#FFFF00"
elif [[ $temp -ge 75 ]]; then
printmain="$temp°C"
printsmall=""
printcolor="#FF0000"
else
printcolor=""
fi
echo "$printmain"
echo "$printsmall"
echo "$printcolor"
##
exit 0