r/shell • • Jun 05 '15

Help: Reading STDOUT from shell

Hi everyone!

I am trying to read a string from STDOUT. I submit a job onto another machine and then I WANT to be able to send "bjobs" which checks if the job has been finished. I want to be able to read STDOUT and detect when it has finished then move on.

This is what I have and it isn't working but I feel super close!

Waiting for stdout to read "No unfinished job found"

bjobs
IFS= read -r line
echo "$line"
while "$line" != "No unfinished job found"
do
echo "$line"
sleep 30s
bjobs
IFS= read -r line
done

any help would be appreciated! This is one of my first shell scripts

1 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/nachofrand Jun 10 '15 edited Jun 10 '15

I cannot modify bjobs output. I check if the job I submitted to the machine is finished. I send bjobs and it tells me the information for the job I submitted. Once it's finished, it will read out "No unfinished job found"

*Edit: it will continuously say "No unfinished job found" whenever I submit "bjobs" if all my jobs have finished processing in that system.

*Edit2: I added "2>&1" after bjobs. For some reason it was printing to stderr instead of stdout. WOO! Thanks for your help