query cpu load every x secs and beep when falls
I run a program that executes cpu and memory hungry jobs. I launch them to come back to the box to see if they are finished.
I'd like to write a simple bash script running in the background that notifies me when the jobs are finished. I guess that I'll combine a simple echo -e "\a" with regular checks of loads ps -eao "pcpu" | awk '{a+=$1} END {print a}' ps -eao "pmem" | awk '{a+=$1} END {print a}' How do I run the last two commands every five seconds, for instance? Thanks! |
If once a minute was good enough, you could make the notifier a cron job (with * * * * *). But probably you'd want the beeping to stop when you're back at the box and got the results.
The simplest might be to enter the big job and the beeper together, e.g., Code:
bigjob; echo -e "\a" BTW, to just see the load, you could use "uptime". |
P.S.,
You asked about doing somehting every 5 seconds. You can put the command "sleep 5" together with your commands in a loop. E.g., in csh Code:
while (1) BTW, this won't run exactly every 5 seconds, because ps and the loop take some time too. |
its a GUI-only program
Oh, sorry, the program is a GUI without command line control. It manipulates digital pictures and I can only know when the jog is over by inspecting the screen, or indirectly by checking the cpu and memory load.
I'd need to apply awk to uptime, as well, right? Thanks. |
I mentioned uptime in case you wanted to look at the load averages just for your information (BTW, top shows them also). If you want to use the output in a script, indeed you have to pick out the number using awk (or cut, or perl, or assigning to a variable then indexing). And then you have to code a comparison of that value to a threshold, and based on the outcome beep or not.
But batch does it all for you -- waiting and checking load, until it drops below 0.8. Then it runs your script, which only needs to beep. |
man batch |lpr :)
Thanks a lot. |
All times are GMT -5. The time now is 02:53 AM. |