Is there a way to programmatically check if there are running and/or queued jobs? I'm looking for a script (can be Bash, Python, or any other typical language) that does that and then take some actions if necessary, e.g., shutdown the server (or in my case, an instance in Google Compute Engine). I'd also like to check if there are other users logged in before taking actions. I know the command qstat
, but not sure how to use it in a script. Same thing for the command who
. I'm using Torque and Ubuntu Server.
Thank you.
EDIT
Given the "down votes", I'll try to give more information. I'd like to do something like the following in pseudo-code:
if "no jobs queued" and "no jobs running" and "no users logged in" then
shutdown machine
endif
Obviously, the missing part is how to detect, in a script file, the conditions within quotes. The shutdown part isn't important here. I'd appreciate if anyone could give me some pointers or share some ideas. Thanks.