Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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.

share|improve this answer

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
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.