0

When I run this command:

bjobs -r -P xenon -W | awk '{print $7}' | grep -v JOB_NAME |
cut -f 1 -d ' ' | xargs

in a terminal, all running JOB_NAMES are coming, but when I do this in per_script only JOB_ID are coming.

Perl script code is below:

@dummy_jobs = qx/bjobs -r -P xenon -W | awk '{print $7}' | grep -v JOB_NAME | cut -f 1 -d ' ' | xargs/;

What needs to be changed in Perl?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    I think `{print $7}` should be in double quotes not in single quotes – Jens Aug 19 '22 at 11:52
  • Check the output of the commend without `grep` – Jens Aug 19 '22 at 11:53
  • Perl is capable to __filter__ out the information of interest on it's own and you would not need to __pipe__ output of one command to other -- it would work much faster. – Polar Bear Aug 19 '22 at 17:16
  • hm ... doesn't `awk '{print $7}'` print the seven-th _space_-delimited field of its input? Then there is nothing for `-d' '` in `cut` as there are no spaces in what `cut` gets...? And what is the pipe to `xargs` for? (Without arguments it only prints what it's given using `echo`) – zdim Aug 19 '22 at 18:01

1 Answers1

3

qx/.../ literals are very much like double-quoted strings. Specifically, $7 is interpolated, so you end up passing ... | awk '{print }' | ....

Replace

qx/...$7.../

with

qx/...\$7.../

Or if you prefer, you can use

my $shell_cmd = <<'EOS';  # These single-quotes means you get exactly what follows.
bjobs -r -P xenon -W | awk '{print $7}' | grep -v JOB_NAME | cut -f 1 -d ' ' | xargs
EOS

my @dummy_jobs = qx/$shell_cmd/;

Another difference is that qx uses /bin/sh instead of whatever shell you were using, but that shouldn't be relevant here.

ikegami
  • 367,544
  • 15
  • 269
  • 518