Read everything that has been echo'd and 'errored' to terminal window?

1

I've inherited a complex shell script running on OSX that gets run on a crontab. Within the script I would like to periodically read everything in the terminal window and write it to another file... sort of as a log file that I can review later.

Im trying to capture things that have been ECHO'd within the script as well as any error messages displayed on the terminal. (ie /Users/topher/program.sh: line 58: Permission denied)

Is this possible? What command can read from the terminal or output of the program?

Thanks! topher

Topher

Posted 2010-10-13T19:31:24.850

Reputation: 11

Answers

0

If the command you run from cron is as following, all output generated will be written to the logfile.log file

/Users/topher/program.sh > logfile.log

The above command will empty the logfile.log file and fill it with output generated by the program.sh script. The below command will append the output.

/Users/topher/program.sh >> logfile.log

BloodPhilia

Posted 2010-10-13T19:31:24.850

Reputation: 27 374

0

Use tee to output to both the screen and a file.

./some/thing | tee thing.log

You might want to redirect stderr to stdout to dump them both to the log file.

    ./some/thing 2>&1 | tee thing.log

Benjamin Bannier

Posted 2010-10-13T19:31:24.850

Reputation: 13 999

0

I don't know about OS X's terminal application, but some terminals such as xterm can be started with an option that logs everything that appears on the display to a file. Another possibility is to run the script program, which captures all characters to and from the terminal to a file.

garyjohn

Posted 2010-10-13T19:31:24.850

Reputation: 29 085