PDA

View Full Version : crontab time issues



Ambrose
06-19-2003, 12:35 AM
Hi

I've added this line to /etc/crontab, the system wide crontab file.
0 0 * * * root /usr/sbin/ntpdate -o 1 tock.usno.navy.mil
NTPDate sync's my machine's time with the above server's time.

The next line in the same file is:
5 0 * * * root date | mail root@localhost
This e-mails me the time

So, after the time is sync'd, I get an e-mail. Perfect!

The problem is, I get an e-mail with the date at 0:00, and another one at 15:00. I've tested this with other lines in the /etc/crontab file ("echo "test at noon" |mail) and again, I get two e-mails.

Anyone else have this problem?
Anyone know how to stop this?

When I started crond, I just did "sudo /etc/init.d/cron start"

Thanks,
- Ambrose

Dave_Bechtel
06-19-2003, 02:49 PM
--In the first line, you have '0 0 *...'
--Second line, you have '5 0 *...' so things aren't happening sequentially the way you expect.

--I am not a cron guru, but suggest you put the ntpdate and mail commands into 1 script file and then run that file at midnight+ 1minute (don't forget to chmod +x it.) This will ensure the mail only arrives after ntpdate runs, and only runs with that file.

--Also do ' ps ax |grep cron ' and see if you have two daemons running.

--Neat idea; thanx for the tip.


Hi

I've added this line to /etc/crontab, the system wide crontab file.
0 0 * * * root /usr/sbin/ntpdate -o 1 tock.usno.navy.mil
NTPDate sync's my machine's time with the above server's time.

The next line in the same file is:
5 0 * * * root date | mail root@localhost
This e-mails me the time

So, after the time is sync'd, I get an e-mail. Perfect!

The problem is, I get an e-mail with the date at 0:00, and another one at 15:00. I've tested this with other lines in the /etc/crontab file ("echo "test at noon" |mail) and again, I get two e-mails.

Anyone else have this problem?
Anyone know how to stop this?

When I started crond, I just did "sudo /etc/init.d/cron start"

Thanks,
- Ambrose

Ambrose
06-20-2003, 01:11 AM
Ah ha!

I didn't think to check to see if two cron's were running, and that was it.

FYI, and 00:05 I get the e-mail with the time, and at 00:00 it sync's ;-)

- Ambrose

Dave_Bechtel
06-20-2003, 12:26 PM
--Yes, I know; but what is the real value of getting a mail at 5 minutes after midnight regardless? Wouldn't you rather get a mail at midnight from the clock-sync script? That lets you know if it ran Ok or not.

--Like so:
' ntpdate parm && date|mail -s "Clock sync script" ' (only sends the mail if return code from ntpdate = 0.) If you *don't* get the mail you know something went wronf. (humor intentional on the sp.)

--With 2 cron entries, the 5-after mail will be sent whether or not the ntpdate has run successfully; with the method above, you will know if it ran Ok.


Ah ha!

I didn't think to check to see if two cron's were running, and that was it.

FYI, and 00:05 I get the e-mail with the time, and at 00:00 it sync's ;-)

- Ambrose