Putting screen output in a log file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Putting screen output in a log file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-02-2007
nsutti nsutti is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 March 2009, 5:15 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck.

Thanks,
Nicole
Sponsored Links
    #2  
Old 11-02-2007
the_anthroid the_anthroid is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 2 November 2007, 2:44 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
i assume you've tried calling the script as:

scriptname -options > outputfile.txt

?
Sponsored Links
    #3  
Old 11-02-2007
nsutti nsutti is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 March 2009, 5:15 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
unix script

This did not work, the program bombed out and put out my standard output. Not sure if this is valid for unix script. It did not like the scriptname.

Thanks
    #4  
Old 11-02-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 AM EDT
Location: classification algos
Posts: 3,203
Thanks: 19
Thanked 30 Times in 27 Posts
the errors might have been meant for stderr rather than stdout

try this,


Code:
programname > logfile 2>&1

Sponsored Links
    #5  
Old 11-05-2007
gus2000 gus2000 is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 17 November 2011, 6:36 PM EST
Posts: 160
Thanks: 0
Thanked 1 Time in 1 Post
Saving the output of unattended scripts

I put this into all of my unattended scripts:



Code:
# Send all output to a logfile and supress input
typeset LOG="/tmp/${0##*/}.out"
mv $LOG ${LOG}.old >/dev/null 2>&1
[[ -t 1 ]] && echo "Writing to logfile '$LOG'."
exec > $LOG 2>&1
exec < /dev/null 2<&1


All stdout and stderr will be logged. Also, since stdin is closed, the script won't hang if any commands wait for input. It will report the logfile name to stdout if run from the command line (attached to a terminal).

This should essentially work the same as the redirection code offered above. If neither is working then something else is wrong, and you'll need post more info about the error.
Sponsored Links
    #6  
Old 11-06-2007
nsutti nsutti is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 24 March 2009, 5:15 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thanks so much

This script worked. Thanks to all of you who helped.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Putting the Current -date in the Output File rymnd_12345 UNIX for Dummies Questions & Answers 5 12-22-2011 05:32 AM
Redirect the output in a file and on screen dynamax Shell Programming and Scripting 3 05-23-2011 12:44 PM
putting color on output file script lhareigh890 Shell Programming and Scripting 3 03-14-2011 06:06 AM
Complete Screen Output to Log File enjoy Shell Programming and Scripting 1 04-26-2010 03:42 PM
how to print script output to screen and file orahi001 UNIX for Dummies Questions & Answers 10 01-16-2009 01:47 AM



All times are GMT -4. The time now is 02:09 AM.