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

i assume you've tried calling the script as:

scriptname -options > outputfile.txt

?

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

the errors might have been meant for stderr rather than stdout

try this,

programname > logfile 2>&1

I put this into all of my unattended scripts:

# 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.

This script worked. Thanks to all of you who helped.