# Changing the format of qstat output

**URL:** <https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827>\
**Category:** Users/Site Administrators\
**Created:** [October 30, 2019, 1:44am UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827 "2019-10-30T01:44:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![datakid](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@datakid](https://community.openpbs.org/u/datakid)\
**Post date:** [October 30, 2019, 1:44am UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827/1 "2019-10-30T01:44:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [October 30, 2019, 1:57pm UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827/2 "2019-10-30T13:57:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vstumpf](https://avatars.discourse-cdn.com/v4/letter/v/dbc845/32.png) [@vstumpf](https://community.openpbs.org/u/vstumpf)\
**Post date:** [October 30, 2019, 6:52pm UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827/3 "2019-10-30T18:52:20Z")

</div>

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:

```auto
[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"
]

```

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [October 30, 2019, 7:18pm UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827/4 "2019-10-30T19:18:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![datakid](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@datakid](https://community.openpbs.org/u/datakid)\
**Post date:** [October 30, 2019, 9:28pm UTC](https://community.openpbs.org/t/changing-the-format-of-qstat-output/1827/5 "2019-10-30T21:28:56Z")

</div>

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\>**
