need to redirect output to 2 places

Posted on 2005-04-22
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
    LVL 34

    Accepted Solution

    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

    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

    ended up doing similar:

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

    Author Comment

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

    Expert Comment

    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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    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.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now