How to capture the output of one shell script into other in unix
10,417
Solution 1
like this?
retval=$(path/to/run_sftp.sh)
now you have done/failed in var retval
. you can do your if check with your logic.
Solution 2
You can capture the output using $(), or the inverse `
So:
if [ $(run_sftp.sh) = 'done' ] then
etc
Solution 3
I am assuming that your script run_sftp.sh will call other statements and produce done message only when it is success and no other commands called by run_sftp.sh will produce done message. In that case you capture output of script run and then grep done
MSG=$(run_sftp.sh)
echo $MSG | grep 'done'
if [ $? -eq 0 ]
then
echo "run"
else
exit 9
fi
Thanks
Author by
Pooja25
Updated on June 05, 2022Comments
-
Pooja25 almost 2 years
I am running one shell script run_sftp.sh whose output will be either "done" or "failed" and I am calling this script into another script which will execute some command if run_sftp.sh output is "done"
If [ Output(run_sftp.sh) = 'done' ] then echo "run" else "Stop running" fi
This is the algorithm. Please suggest.
-
Pooja25 over 10 yearsI am executing other commands also so there will be other outputs except Done and Failed, but I want to capture only done, then in that case how should I capture only done from command output?
-
Pooja25 over 10 yearsI am executing other commands also so there will be other outputs except Done and Failed, but I want to capture only done, then in that case how should I capture only done from command output?
-
Kent over 10 yearsregex match check @Pooja25
-
Pooja25 over 10 yearsI am using
retval=$(sh run_sftp.sh)
cat $retval | grep "Done"
but it is not working -
Kent over 10 yearsit won't work, if you want to use grep, try
grep -qi "done" <<< $retval
and check the return code of the grep. @Pooja25