3

Here is my content of sudo crontab -e

    @hourly /home/userName/ntpdate.sh

The content of my script (ntpdate.sh) //.25 is my ntp server

     echo "Current time is $(date), " >> /home/userName/ntpdateLog.txt
     ntpdate -u 192.168.1.25 >> /home/userName/ntpdateLog.txt

When I simply run the command by itself, or run the script by itself, it works fine and outputs to the file. The script has correct permissions to run.

The error I'm getting in /var/log/syslog is this:

    CRON[6386]: (root) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
    postfix/sendmail[6410]: fatal: open /etc/postfix/main.cf: No such file or directory

Why is there a mail error when the script doesn't need mail (that I know of).

I know that ntpdate is deprecated, but it is the only thing that does what I need right now (assuming I can get cron to run it).

3
  • 2
    cron runs in a minimal shell with minimal features and thus failure to use the full path is the most common problem. Although you included the full path in your script, within your script you do not. Use the full path to ntpdate and where you want ntpdateLog.txt to be written.
    – Panther
    Jul 21, 2014 at 18:28
  • That makes sense, but it doesn't appear to be a problem. I'll change the script to reflect those changes Jul 21, 2014 at 20:06
  • Set up ntpd and forget about ntpdate. Jul 22, 2014 at 17:35

1 Answer 1

9

According to cron manual:

  When executing commands, any output is  mailed  to  the  owner  of  the
  crontab (or to the user named in the MAILTO environment variable in the
  crontab, if such exists)

If you want to stop mail alert, you should redirect standard output and standard error.

So you should modify your cron file as:

  @hourly /home/userName/ntpdate.sh >> /home/userName/ntpdateLog.txt 2>&1

and your script:

  echo "Current time is $(date), "
  ntpdate -u 192.168.1.25

Another way to do this is give an empty value to MAILTO variable at the top of your cron file:

  MAILTO=""
  @hourly /home/userName/ntpdate.sh >> /home/userName/ntpdateLog.txt 2>&1

I suggest you redirect std output and std error in any case because it is easier to debug the script in case of errors.

Here is crontab manual for more details.

You must log in to answer this question.

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