Redirecting to standard output from within called script

Hi,

How to achieve this? Let us assume the following:

There are 2 scripts a.ksh and b.ksh

$ cat a.ksh
sh b.sh 2>&1 >> /work/log/a_log.txt

$ cat b.sh
echo "abcd"

My requirement is, is there a way to display this abcd in standard output also alongside of writing into a_log.txt? Please help me out in this. Appreciate your help.

Regards,
Vignesh

Hi,

Try the following:
sh b.sh | tee -a /work/log/a_log.txt

"tee -a " write to the standart output and to a log file parallely.

Regards,
Nir

Hi Nir,

But the problem is the script (here b.sh) is a common script that is called by a lot of scripts that are coded in this way. It is difficult to modify those scripts. So please suggest me if there is a way to do that in b.sh itself.

Thanks,
Vignesh

Hi,

Make the following changes in b.sh

echo "abcd" | tee /dev/tty

This should do the trick and you would get the data in the file as well as standard output.

PS: Sorry, i just noticed that you wanted changes done in a.sh and not b.sh. Please ignore this one.

Use:

sh b.sh 2>&1| tee -a /work/log/a_log.txt

Hi,

I want the change to be done in b.ksh only.

echo "abcd" | tee /dev/tty does not seem to be working.

Do you have any other suggestions? :confused:

Thanks,
Vignesh

Then try:

$ cat a.ksh
sh b.sh 2>&1 |tee -a /work/log/a_log.txt
2>&2
# rest here

Hi Klash, I cannot change a.ksh. I can change only b.ksh.

b.sh:

[code]
exec 1>&2 | tee -a /work/log/a_log.txt
.............. the rest of othe b.sh .............

[code]