Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I would like to have a service watchdog script echo the status to the screen if called like ./watchdog.sh but if it is run by cron, there is no need to echo output. What is the proper method? Where does stdout go when a script is run under root's crontab?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

For the many cron jobs that I run, I purposely make them so if run on command line appropriate outout is generated but the same script if placed in crontab I always capture both the stdout and stderr to a log file:

00 12 * * 1-5 /home/aws/bin/myscript.sh >> /home/aswartz/rje/cron.log 2>&1

share|improve this answer

Cronjob output is sent to the user via the system's mail system.

You can check whether stdout is a terminal:

if [ -t 1 ]; then
     echo Terminal
else
     # not a terminal, don't echo
fi
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.