Linux – Crontab running when it pleases (fixed.. in a way)

cronlinuxphp5Ubuntu

I have the following line in the crontab:

 */30 * * * * /usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php

This script updates my no-ip account. It also writes to a log file saying what it did and did not due.

This is today's log file:

2009/08/06 11:30 - A tentar buscar ip
2009/08/06 11:30 - Ip encontrado - ***.***.***.***
2009/08/06 11:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 12:00 - A tentar buscar ip
2009/08/06 12:00 - Ip encontrado - ***.***.***.***
2009/08/06 12:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 12:30 - A tentar buscar ip
2009/08/06 12:30 - Ip encontrado - ***.***.***.***
2009/08/06 12:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 13:00 - A tentar buscar ip
2009/08/06 13:00 - Ip encontrado - ***.***.***.***
2009/08/06 13:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 13:30 - A tentar buscar ip
2009/08/06 13:30 - Ip encontrado - ***.***.***.***
2009/08/06 13:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 14:00 - A tentar buscar ip
2009/08/06 14:00 - Ip encontrado - ***.***.***.***
2009/08/06 14:00 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 14:30 - A tentar buscar ip
2009/08/06 14:30 - Ip encontrado - ***.***.***.***
2009/08/06 14:30 - Ip nao alterado - Abortar acesso ao no-ip
2009/08/06 15:00 - A tentar buscar ip
2009/08/06 15:00 - Ip encontrado - ***.***.***.***
2009/08/06 15:00 - Ip nao alterado - Abortar acesso ao no-ip

As you can see by the timestamp, today it started at 11:30 and then stopped and 15:00.

Also the cron is running:

antoniocs@acsserver:~$ /etc/init.d/cron status
 * cron is running

I don't know why this is happening. Some days ago this was running with out a problem (I have entries in the log every 30m). The only thing I did was recently upgrade my Ubuntu-Server (which has caused me some other problems)

Am I doing anything wrong here? Have the updates messed up cron??

EDIT:

This is what I have in the syslog for 7/8/09 at 15:00 (This is today's log but the same thing happened it stopped after 15:00)

146 Aug  7 15:00:01 acsserver CRON[30775]: Mount of private directory return code [0]
147 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30786]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
148 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30811]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
149 Aug  7 15:00:01 acsserver /USR/SBIN/CRON[30810]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd hourly 2>/dev/null)

There doesn't seem to be any errors 🙁

EDIT 2:
After looking at the syslog file I noticed these lines:

Aug  7 22:10:01 acsserver /USR/SBIN/CRON[6023]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:17:01 acsserver /USR/SBIN/CRON[6158]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  7 22:20:01 acsserver /USR/SBIN/CRON[6207]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:30:01 acsserver CRON[6336]: Mount of private directory return code [256]
Aug  7 22:30:01 acsserver /USR/SBIN/CRON[6350]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:30:01 acsserver /USR/SBIN/CRON[6354]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
Aug  7 22:30:01 acsserver postfix/sendmail[6367]: fatal: open /etc/postfix/main.cf: No such file or directory
Aug  7 22:39:01 acsserver /USR/SBIN/CRON[6523]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm)
Aug  7 22:40:01 acsserver /USR/SBIN/CRON[6574]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 22:50:01 acsserver /USR/SBIN/CRON[7044]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 23:00:01 acsserver CRON[7173]: Mount of private directory return code [256]
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7193]: (antoniocs) CMD (/usr/bin/php /home/antoniocs/phpscripts/update-noip/update-noip.php )
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7195]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd hourly 2>/dev/null)
Aug  7 23:00:01 acsserver /USR/SBIN/CRON[7196]: (root) CMD ([ -x /usr/sbin/update-motd ] && /usr/sbin/update-motd 2>/dev/null)
Aug  7 23:00:01 acsserver postfix/sendmail[7211]: fatal: open /etc/postfix/main.cf: No such file or directory
Aug  7 23:09:01 acsserver /USR/SBIN/CRON[7390]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm)

So it is running the php script.
I just don't know what /etc/postfix/main.cf is. In my php script I only use curl to make some connections.

EDIT 3:

Seems that the problem really was the postfix.
I followed these instructions -> https://help.ubuntu.com/7.04/server/C/postfix.html
and just set up the main.cf file that the cron was complaining about and the php script now seems to be okay.

Still don't fully understand why this was happening. If anyone has any theory on why the heck this happened and why I needed the postfix to run my php script, please let me know!!

Thanks for all the help guys!

PS: Also if anyone knows what the mount error is please also tell me 🙁

Best Answer

Your final "EDIT 2" logfile shows that your postfix system isn't set up properly. When a cron script sends output to stdout or stderr (eg, any error messages in the script) , it sends an email (to root@localhost by default), and you need a working mail server for that to happen.

It looks very much like your script is failing for some other reason and is writing something to stderr or stdout, but because you don't have a working postfix setup you're losing that information. It's quite likely those error emails have the information you need to work out why your script is failing.

That, of course, is assuming this isn't your error: Aug 7 22:30:01 acsserver CRON[6336]: Mount of private directory return code [256]

Either way, you should fix your postfix setup.