Issue
In slurm, calling the command squeue -u <username>
will list all the jobs that are pending or active for a given user. I am wondering if there was a quick way to tally them all so that I know how many outstanding jobs there are, including pending and actively running jobs. Thanks!
Solution
If you just want to summarize the output of squeue
, how about:
squeue -u <username> | awk '
BEGIN {
abbrev["R"]="(Running)"
abbrev["PD"]="(Pending)"
abbrev["CG"]="(Completing)"
abbrev["F"]="(Failed)"
}
NR>1 {a[$5]++}
END {
for (i in a) {
printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
}
}'
which yields something like:
R (Running) 1
PD (Pending) 4
Explanations:
- The
job state
is assumed to be in the 5th field according to the default format ofsqueue
. - Then the script counts the appearance of each job state code except for the 1st line which includes the header.
- Finally it reports the count of each job state code.
In order to make it handy, add the following lines to your .bash_aliases
or .bashrc
(the filename may depend on the system):
function summary() {
squeue "$@" | awk '
BEGIN {
abbrev["R"]="(Running)"
abbrev["PD"]="(Pending)"
abbrev["CG"]="(Completing)"
abbrev["F"]="(Failed)"
}
NR>1 {a[$5]++}
END {
for (i in a) {
printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
}
}'
}
Then you can invoke the command just with summary [option]
, where [option]
accepts options to squeue
if needed (mostly unnecessary).
Hope this helps.
Answered By - tshiono Answer Checked By - Timothy Miller (WPSolving Admin)