Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"allowed" operations in bash read while loop

I have a file text.txt which contains two lines.

first line
second line

I am trying to loop in bash using following loop:

while read -r LINE || [[ -n "$LINE" ]]; do
   # sed -i 'some command' somefile
   echo "echo something"
   echo "$LINE"
   sh call_other_script.sh

   if  ! sh some_complex_script.sh   ; then
        echo "operation failed"
   fi

done <file.txt

When calling some_complex_script.sh only the first line is processed, however when commenting it out all two lines are processed. some_complex_script.sh does all kind of stuff, like starting processes, sqlplus, starting WildFly etc.

./bin/call_some_script.sh | tee $SOME_LOGFILE &
wait

...

sqlplus  $ORACLE_USER/$ORACLE_PWD@$DB<<EOF
whenever sqlerror exit 1;
whenever oserror exit 2;
INSERT INTO TABLE ....
COMMIT;

quit;
EOF

...
nohup $SERVER_DIR/bin/standalone.sh -c $WILDFLY_PROFILE -u 230.0.0.4 >/dev/null 2>&1 &

My question is if there are some operations which are not supposed to be called in some_complex_script.sh and in the loop (it may as well take 10 minutes to finish, is this a good idea at all?) which may break that loop. The script is called using Jenkins and the Publish over SSH Plugin. When some_complex_script.sh is called on its own, there are no problems.

like image 957
user140547 Avatar asked Apr 26 '26 18:04

user140547


1 Answers

You should close or redirect stdin for the other commands you run, to stop them reading from the file. eg:

 sh call_other_script.sh </dev/null
like image 181
meuh Avatar answered Apr 28 '26 12:04

meuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!