Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a simple way to determine whether a shell script was initiated via cron or manually by the user? In my case, I want the script to send output to a log file when run via cron, but to stdout when initiated manually.

share|improve this question
up vote 3 down vote accepted

What about simply setting up the command in the crontrab to redirect stdout to a file (>> for append)?

Something like:

XX XX XX XX XX /path/to/cmd >> outputfile.log

share|improve this answer
My, that was simple. Thanks. – eykanal May 9 '11 at 20:18

Your Answer


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.