Changing the format of qstat output

Is there a way to alter the output format of qstat?

Let’s say - hypothetically - I just want a list of all users with a job in the queue. I could do

qstat -a | cut -d' ' -f2 | sort | uniq

But I’d like to do

qstat --format="Username"

or something like that.

Other things I’d like to do which I can’t quite glean from the documents:

“only running jobs”
“only interactive jobs”

etc

Please try these commands:

  • qstat -u username | tail -n +6 | column -t #to get the user details
  • qstat -a | tail -n +6 | column -t # to get formatted details
  • qstat -r | tail -n +6 | column -t # to get only RUNNING Jobs

Please check man pages for qstat and qselect

If you don’t mind using a different command, and don’t mind having it formatted in json, you can output qstat to json and use jq to process it.
This is what I used to get unique users in a queue:

[vstumpf@shecil ~]$ qstat
Job id            Name             User              Time Use S Queue
----------------  ---------------- ----------------  -------- - -----
1000066.shecil    STDIN            pbsuser           00:00:00 R workq
1000067.shecil    STDIN            vstumpf           00:00:00 R workq
1000068.shecil    STDIN            vstumpf           00:00:00 R workq
1000069.shecil    STDIN            vstumpf           00:00:00 R workq
1000070.shecil    STDIN            pbsuser                  0 Q workq
1000071.shecil    STDIN            pbsuser1                 0 Q workq
1000073.shecil    STDIN            pbsuser2                 0 Q exprq
[vstumpf@shecil ~]$ qstat -f -Fjson | jq '.Jobs | map(select(.queue == "workq") | .euser) | unique'
[
  "pbsuser",
  "pbsuser1",
  "vstumpf"
]
[vstumpf@shecil ~]$ qstat -f -Fjson | jq '.Jobs | map(select(.queue == "exprq") | .euser) | unique'
[
  "pbsuser2"
]

FWIW, before there was the option for JSON output, we used the option when building qstat to enable a built-in TCL interpreter. With that, you could supply TCL scripts that qstat would use to format output. For example, here is our standard qstat output:

$ qstat -a
pbspl233b.nas.nasa.gov:     Wed Oct 30 12:04:37 2019
 Server reports 6 jobs total (T:0 Q:0 H:5 W:0 R:1 E:0 B:0)

  Host         CPUs Tasks Jobs Info
  ----------- ----- ----- ---- -------------------
   1116 hosts 13392     0   -- wes
     34 hosts    84     0   -- wes down
    379 hosts  4548  4548   -- wes in-use
    227 hosts   648     0   -- wes offline
     18 hosts   216     0   -- wes q=diags
  r733i2n3        0     0    0 wes q=diags offline
  r789i2n13       0     0    0 wes q=diags offline
     16 hosts    96     0   -- wes {offline down}

                                          Req'd     Elap       Rem
SeqNo  User     Queue Jobname    CPUs Nds wallt Ss wallt Eff wallt
------ -------- ----- ---------- ---- --- ----- -- ----- --- -----
633184 userfred long  HLSchem30m 4548 379 16:00 R  04:40 93% 11:20
633153 usertom  long  merwesC64     6   6 02:40 Hs    --  -- 02:40
633154 usertom  long  merwesC128   12  12 01:20 Hs    --  -- 01:20
633155 usertom  long  merwesC256   22  22 01:00 Hs    --  -- 01:00
633156 usertom  long  merwesC512   43  43 01:00 Hs    --  -- 01:00
633157 usertom  long  merwesC102   86  86 00:30 Hs    --  -- 00:30

To get the user list as you asked for, I can run:

$ qstat -W sumjobs=1,user -W o=user,cnt
User     Cnt
-------- ---
userfred   1
usertom    5

Here, I asked qstat to summarize similar jobs, using the user name as the key, and to display only the user name and the count of similar jobs.

Buried somewhere on my todo list is to convert our embedded TCL scripts into a JSON post-processor.

Thanks everyone! I’m from the Slurm world, I didn’t realise I’d become so addicted to squeue’s -o <output_format>, --format=<output_format>