Infodayne Infodayne - 1 year ago 70
Bash Question

Call script A from script B, and write output of script A to file

I have two scripts, A and B.

I need to capture all the terminal output from script A into a file. I know that I can do this:

A |tee myfile.log
, or
A > myfile.log

However, when I do it from script B, it doesn't work (script A runs fine but output not redirected).

Ex. Script A:

echo "I'm script A"

Ex. Script B:

echo "Starting script B"
A |tee myfile.log
echo "Finished script B"



I'm script A

Answer Source

This seems to work well enough for me. You need ./ because script 'a' is not in your $PATH. The ./ says 'look in the current directory for my script rather than looking at all the directories specified in $PATH'.

echo "Starting script B"
./ | tee myfile.log
echo "Finished script B"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download