Created
February 14, 2019 19:48
-
-
Save Finesim97/5346c0e43928028c819754400dcc81b6 to your computer and use it in GitHub Desktop.
A small bash function, which checks, whether the given host runs a job in the grid. (hostname is just host on some systems!)
This file contains 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 | |
# This function takes a hostname as an argument and returns | |
# 0 when the given host has at least 1 job running 0 if it has | |
# no job (or future). | |
function hasHostActiveJobs(){ | |
hostname=$1 | |
qhostout=$(qhost -j -xml -l hostname=$hostname) # Option seems to be called host on other systems | |
#echo $qhostout | |
filterstring="name='job_state'>r" # Just remove the r for any job | |
[[ $qhostout == *$filterstring* ]] | |
return $? | |
} | |
if hasHostActiveJobs $(hostname); then | |
echo "I have a job!" | |
else | |
echo "No job for me." | |
fi | |
# Test with | |
# echo sleep 3 | qsub -l hostname=$(hostname) && watch -n1 bash isGridJobRunning.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment