Pooja25
Pooja25

Reputation: 326

How to capture the output of one shell script into other in unix

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.

Upvotes: 2

Views: 15075

Answers (3)

anonymous
anonymous

Reputation: 1968

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

Upvotes: 0

Kent
Kent

Reputation: 195059

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.

Upvotes: 8

sharcashmo
sharcashmo

Reputation: 815

You can capture the output using $(), or the inverse `

So:

if [ $(run_sftp.sh) = 'done' ] then

etc

Upvotes: 2

Related Questions