Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save InbarRose/8745afacbb5fa8f44cc6728c9988c6d3 to your computer and use it in GitHub Desktop.
Save InbarRose/8745afacbb5fa8f44cc6728c9988c6d3 to your computer and use it in GitHub Desktop.
single line script to check if the CPU usage is above a certain threshhold on the device. and return exit code 0 if not, 1 if it is.
cpu_threshhold=80 ; cpu_idle=$(top -b -n 1 | grep Cpu | awk '{print $8}'|cut -f 1 -d '.') ; cpu_usage=$(expr 100 - $cpu_idle) ; if [ $cpu_usage -gt $cpu_threshhold ]; then exit 1; else exit 0; fi
cpu_threshhold=80 ; cpu_idle=$(top -b -n 1 | grep Cpu | awk '{print $8}'|cut -f 1 -d '.') ; cpu_usage=$(expr 100 - $cpu_idle) ; /bin/sh -c "echo $cpu_usage ; if [ $cpu_usage -gt $cpu_threshhold ]; then exit 1 ; else exit 0; fi"
@InbarRose
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment