1

I would like to combine the outputs of sprio and squeue so that I can see JobId, Name, Priority, Age, State and Time in a one-liner without the use of files. I thought I could do this using awk, paste and some piping, but I don't know enough bash syntax to do anything other than getting the outputs to print consecutively.

{ sprio -u manninm; squeue -u $USER; } | paste

I would like to get certain columns of each output to print side by side, rather but I can only get the two outputs to print consecutively. If someone could point me to some resources or provide some suggestions, thanks.

JOBID PARTITION     USER   PRIORITY        AGE  FAIRSHARE    JOBSIZE  PARTITION                 TRES
         284926 standard   $USER     196140        117      95896        128     100000
JOBID PARTITION     NAME     USER  ACCOUNT ST       TIME  NODES NODELIST(REASON)
            284938  standard SM.fastq  manninm kretzler PD       0:00      1 (Priority)

Edit: So after reading a little of the awk Tutorial, what I am actually wanting to print to the screen is fields 1-9 of the squeue command, and fields 1 and 4 of the sprio command.

{ squeue -u manninm; sprior -u $USER; } |

creates two records, and I would like fields 1:9 of record 1 and fields 1 and 4 of record two to print column wise to the screen. It doesn't seem to be as easy as I had hoped.

Manninm
  • 151
  • 1
  • 7
  • work your way thru the [Awk Tutorial](http://grymoire.com/Unix/Awk.html) . Good luck. – shellter Sep 04 '19 at 16:08
  • It sounds like you're trying to "matrix transpose" your output. Instead of `paste` above, try implementing the `awk` code in the top answer to this question, and piping your output into that instead: https://stackoverflow.com/questions/1729824/an-efficient-way-to-transpose-a-file-in-bash – Jeff Y Sep 04 '19 at 16:57

2 Answers2

1

The squeue command can give you the priority. It accepts a --output parameter that you can use to choose the columns you want squeue to display through a printf-style format string. By default, it is

squeue --output "%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R"

so if you add %p or %Q you will get an additional column in the output with the job priority.

squeue --output "%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R %p"

or

squeue --output "%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R %Q"

The difference between %p and %Q is that the former gives the priority as a floating point number while the latter gives it as an integer.

Note that squeue also accepts --Format (capital 'F') which takes a list of column names rather than a format string.

You will not get the details of the factors of the priority, though. If you want that, you will need indeed to merge the outputs of squeue and sprio. Be sure though to sort the outputs and to make sure only pending jobs are listed by squeue otherwise you cannot be sure that the correct lines are merge together with awk.

The best option in that case is to use the merge command that will reconcile outputs of both commandes based on the jobid:

join <(squeue -t PD | sort -n) <(sprio | sort -n) | column -t
damienfrancois
  • 52,978
  • 9
  • 96
  • 110
  • Thank you for. squeue -u $USER -o "%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R %Q" gives the output I wanted. – Manninm Sep 05 '19 at 15:04
0

Using the "matrix transpose" idea linked in my comment above, but simplifying it down to "two rows at a time", which is what you seem to be shooting for, try this awk one-liner instead of paste:

bash { sprio -u manninm; squeue -u $USER; } | awk 'NR%2 {split($0,a)} !(NR%2) {for(i=1;i<=NF;++i) print a[i],$i}'
Jeff Y
  • 2,437
  • 1
  • 11
  • 18