linuxshelllsf

Why lsf command bjobs can not be executed correctly in linux shell


In my project, I write a linux shell script. I want to distinguish the node whether the jobs is running in lsf. LSF is IBM product.

I have a file Date.log, the content is like:

 133462 bio-yuym 5*r01n42
 141588 eee-leisq 40*r10n43
 142885 phy-zhangy 40*r13n40
 142907 phy-zhangy 40*r13n31
 143545 bio-zouxd r01n07
 143962 phy-xiaoxl 40*r08n38
 143971 eee-leisq 40*r08n53
 144009 phy-muhm 40*r11n51

My linux shell script code is:

cat Date.log | while read LINE     
do
  jobID=`echo $LINE | awk '{print $1}'`
  jobInfo=`bjobs $jobID `

  if [[ $jobInfo =~ "not\ found" ]]
  then
     echo $LINE >> "$Date"-lsffin.log
  else
     echo $LINE >> "$Date"-lsfrun.log
 fi
done

The correct result should be two files, and the content of "$Date"-lsfrun.log should be:

143545 bio-zouxd r01n07
143962 phy-xiaoxl 40*r08n38

But it is unlucky, I got messages in my screen:

Job <143545> is not found
Job <143962> is not found

And it is blank in "$Date".lsfrun.log. All the content is in "$Date"-lsfrun.log.

Why lsf command bjobs can not be executed correctly in linux shell?


Solution

  • The fact that you see output to the screen despite capturing the program's standard output indicates that bjobs is writing those error messages to its standard error stream rather than to its standard output stream. That would be utterly conventional.

    If you want to capture both standard output and standard error, then you must redirect the latter into the former:

    jobInfo=`bjobs $jobID 2>&1`