Created
July 27, 2018 21:40
-
-
Save lrdgz/a36dc02d38bbfc34d25d4982228a16e5 to your computer and use it in GitHub Desktop.
cpu temp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# by Luis Rodriguez (developer0606@gmail.com) | |
PREV_TOTAL=0 | |
PREV_IDLE=0 | |
while true; do | |
# Get the total CPU statistics, discarding the 'cpu ' prefix. | |
CPU=(`sed -n 's/^cpu\s//p' /proc/stat`) | |
IDLE=${CPU[3]} # Just the idle CPU time. | |
# Calculate the total CPU time. | |
TOTAL=0 | |
for VALUE in "${CPU[@]}"; do | |
let "TOTAL=$TOTAL+$VALUE" | |
done | |
# Calculate the CPU usage since we last checked. | |
let "DIFF_IDLE=$IDLE-$PREV_IDLE" | |
let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL" | |
let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10" | |
echo -en "\rCPU: $DIFF_USAGE% \b\b" | |
# Remember the total and idle CPU times for the next check. | |
PREV_TOTAL="$TOTAL" | |
PREV_IDLE="$IDLE" | |
# Wait before checking again. | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment