need to redirect output to 2 places

Posted on 2005-04-22
Medium Priority
Last Modified: 2013-12-27
i work for a company and we have a ksh script that does a bcp.
lets say:
ScriptA.ksh > /home/user/ScriptA.out 2>&1 & 

Inside <ScriptA> i have the following code in place to check for BCP fails:
$SYBASE/bin/bcp <tablename> in <filename.bcp> -U$SYB_USER -P$SYB_PASS -S$DSQUERY -c -t "|" -r "\n" > /home/user/bcp.out

i then check home/user/bcp.out for success/fail. But for audit purpose or just to be able to look back i want the same output directed to /home/user/bcp.out to also write to home/user/ScriptA.out
Question by:pdadddino
  • 3
LVL 34

Accepted Solution

PsiCop earned 2000 total points
ID: 13844690
Create ScriptA1.ksh:

/<path>/ScriptA.ksh > /home/user/ScriptA.out 2>&1 &
more /home/user/bcp.out >> /home/user/ScriptA.out

That will append the contents of bcp.out to ScriptA.out

Author Comment

ID: 13845068
the real problem is i dont know the name of output file ScriptA.out from inside the script. is there any way to capture it from inside the script?

Author Comment

ID: 13845683
ended up doing similar:

cat home/user/bcp.out >>&1

Author Comment

ID: 13845722
to be exact:
cat home/user/bcp.out >&1
LVL 10

Expert Comment

ID: 13854150
Even though I may be a little late, the command you are looking for is called "tee"

ScriptA.ksh | tee /home/user/bcp.out > /home/user/ScriptA.out

tee is taking what he gets from standartinput is putting it to a file and is writing it to the output again.

You may even do like this:

ScriptA.ksh | tee /home/user/bcp.out | tee /home/user/ScriptA.out

which will send it to the two logfiles AND display it at the screen so that you can see it immediatly.

Pretty usefull also in debugging a line like this:

cat somefile | grep firstsearch | tee resultsafterfirst | grep secondsearch | tee resulataftersecondsearch | grep thirdsearch

as you can see what is passed from one command to the other.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question