I’m having issues with a bash script. Basically, in my script I run the command
bjobs -u $1
$1 is the script argument, and it’s the id of a user on my cluster. If user $1 has no running/pending jobs on the cluster, bjobs prints
No unfinished jobs found
to stdout. Also, exit status is 255. If user $1 does have jobs, bjobs print:
JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME
45823 .......
45824 .......
.
.
and exit status is 0. I would like awk to parse the output of bjobs. I tried
bjobs -u $1 | awk '...'
where ‘…’ is my awk parsing program. This doesn’t work so well, because apparently when user $1 doesn’t have running/pending jobs, the string “No unfinished jobs found” is not passed to awk. The same happens with
bjobs -u $1 > foo
awk '...' foo
Any suggestions?
Maybe that message (being an error of sorts, I guess) is coming to STDERR not STDOUT.
You can redirect IO streams in bash with > to file descriptors, and 2 is STDERR.
Try:
And see if that solves it for you. The 2>&1 part means redirect STDERR (2) to STDOUT (1), and STDOUT is what is piped into awk.
More info: http://www.tldp.org/LDP/abs/html/io-redirection.html