Last active
July 26, 2022 11:59
-
-
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.
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks to: https://fedingo.com/shell-script-to-get-cpu-and-memory-utilization/ for inspiration