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

3 Answers 3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .