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

I have a file called /scripts/checkInternet and it contains:


rm /tmp/
$WGET -q --tries=10 
           --timeout=5 -O /tmp/ &> /dev/null
if [ ! -s /tmp/ ];then
        echo "Nope"
        ifdown eth0.4
        ifup eth0.4
        iptables-restore < /etc/iptables.rules
        echo "Connected"
rm /tmp/

I did chmod +x 755 this file. I can run it as root, but adding it to a cron as root it doesn't function.

What went wrong? The cron itself is being run. I see CMD (/scripts/checkInternet) in my system logs but the desired outcome is missing.

share|improve this question
up vote 5 down vote accepted

99% of all issues running things from cron are caused because of invalid $PATH. I'm betting ifdown, ifup, and iptables-restore are all missing from the default $PATH. You need to specify the absolute path to these.

share|improve this answer
Patrick, you rock. – Matt Mar 14 '12 at 4:24

The cron itself is being run. I see CMD(/scripts/checkInternet) in my system logs but the desired outcome is missing.

Think about that for a moment. If your script generates output or errors, then where would you expect the output to go?

On most Linux/Unix systems, if your script produces any output (e.g. Any output to STDOUT, or any errors to STDERR) then it will be sent via email to the owner of the crontab. In most cases, this is 'root'.

Debian's man page for cron says:

cron will look at MAILTO if it has any reason to send mail as a result of running commands in "this" crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent. Otherwise mail is sent to the owner of the crontab.

So, check the mail for the user who own's this crontab, or for the user specified by MAILTO. That email should contain the error that you are looking for.

When testing, I personally prefer to send any error logs or errors to a file, like this:

   5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1

Or I send it to syslog using logger, like this:

   5 0 * * *       $HOME/bin/daily.job 2>&1 | logger

And then run tail -f logfile in a second window.

share|improve this answer

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.