Created
July 11, 2022 05:33
-
-
Save joseche/019faf5f4c9b06cddff20fc20153d9ad to your computer and use it in GitHub Desktop.
Shell to run something when CPU IDLE > 99
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
| #!/usr/bin/env bash | |
| # check systems idle time, run commands depending on that | |
| function get_idle { | |
| idle=$(top -bn2 | grep "Cpu(s)"|tail -n 1|sed "s/.*, *\([0-9.]*\)%* id.*/\1/") | |
| echo "$idle" | |
| } | |
| function main_loop { | |
| while true; do | |
| idle="$(get_idle)" | |
| if [[ $idle > 99 ]] | |
| then | |
| echo "Do stuff now: $idle" | |
| else | |
| echo "Stop doing stuff now: $idle" | |
| fi | |
| sleep 30 | |
| done | |
| } | |
| main_loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment