diff --git a/README.md b/README.md index 8f56fce..5c8a197 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/i3block_shell/coretemp.sh b/i3block_shell/coretemp.sh new file mode 100755 index 0000000..9aad4fc --- /dev/null +++ b/i3block_shell/coretemp.sh @@ -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