Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output to screen and file

Status
Not open for further replies.

heprox

IS-IT--Management
Dec 16, 2002
178
US
I have a Korn script that runs nightly that I'm trying to get to display to both the screen and write to an output file. I thought I could just use the "tee" command but I keep getting an empty file. In my script I have:

#!/bin/ksh
DATE=$(date +%m%d%y)
ksh -x str_process_main | tee /tmp/str_process_${DATE}.txt

...I thought that this would just run the "str_process_main" script, display it to the terminal and write it to a file?

 
tee will only capture stdin, is the previous script writing to stdout or stderr? Or are you trying to capture the output generated by the -x flag, which I believe will go to stderr...
 
Correct, I'm trying to capture the output of the -x flag. Previously when we ran that script, you could see nothing, I want my admins to be able to see the script as it processes. Is there a way to capture stderr?
 
ksh -x str_process_main 2>&1 | tee /tmp/str_process_${DATE}.txt

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

 
maybe also "script" command will do it:

# script /tmp/my_output
Script command is started. The file is /tmp/my_output.
# date;date
Mon Nov 15 10:15:58 CUT 2004
Mon Nov 15 10:15:58 CUT 2004
# date
Mon Nov 15 10:16:00 CUT 2004
# exit
Script command is complete. The file is /tmp/my_output.
# cat /tmp/my_output
Script command is started on Mon Nov 15 10:15:53 CUT 2004.
# date;date
Mon Nov 15 10:15:58 CUT 2004
Mon Nov 15 10:15:58 CUT 2004
# date
Mon Nov 15 10:16:00 CUT 2004
# exit

Script command is complete on Mon Nov 15 10:16:01 CUT 2004.
#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top