1

I have placed the following information into my crontab file by entering "crontab -e" (in both root and "ubuntu" users, on a 32 bit Canonical Ubuntu AWS instance):

@reboot /usr/bin/php /usr/share/nginx/www/cron/updateIp.php

I have also tried:

@reboot /usr/bin/php /usr/share/nginx/www/cron/updateIp.php >> /home/ubuntu/crontab.log

And /home/ubuntu/crontab.log contains nothing after two reboots.

I imagine that php and/or nginx is not loaded when this cronjob is attempting to run?

Without any error logs to check however, I am at a loss as to what to do next..?

EDIT: Even after logging into the box via SSH with the same user that the crontab -e was created under... the cronjob does not run.

EDIT 2: (results of syslog):

Nov  9 13:29:02 ip-10-122-254-128 CRON[603]: (root) CMD (php /usr/share/nginx/www/cron/updateIp.php)
Nov  9 13:29:02 ip-10-122-254-128 CRON[604]: (ubuntu) CMD (/usr/bin/php /usr/share/nginx/www/cron/updateIp.php >> /home/ubuntu/crontab.log 2>&1)

EDIT 3: This link actually provided the answer I was looking for. Apparently I needed to install php-cgi and mention it specifically, even though whereis php does not show it? Simply installing php5-cgi and changing /usr/bin/php to /usr/bin/php-cgi worked like a charm. I already had php5-cli and php5-fpm installed so I figured php5-cgi wasn't necessary, but I suppose it must have been.

darkAsPitch
  • 1,931
  • 4
  • 25
  • 42
  • What AMI id are you running? In what EC2 region? – Eric Hammond Nov 08 '11 at 03:16
  • 1
    Try this `>> /home/ubuntu/crontab.log 2>&1`. – quanta Nov 08 '11 at 03:18
  • 1
    As with any cron problem, the first place you should look at is the environment, quickly followed by permissions. – Zoredache Nov 08 '11 at 08:35
  • @EricHammond I am running ami-a7f539ce (32 bit oneric) in us-east-1. – darkAsPitch Nov 08 '11 at 16:18
  • @quanta, tried that, crontab.log is empty upon reboot. – darkAsPitch Nov 08 '11 at 16:51
  • @Zoredache, well I am able to run the command from the command line whilst logged in via SSH, and am only adding the commands via **crontab -e** so one would assume I have the correct environment and permissions, no? – darkAsPitch Nov 08 '11 at 16:52
  • No, one would not assume that. When you are logged in via an interactive session many things like the PATH variable and so on, are set much differently then what you see while running under cron. – Zoredache Nov 08 '11 at 17:33
  • I have explicitly set the PATH to the php script in the crontab command. Is there something I am missing? – darkAsPitch Nov 08 '11 at 17:38
  • Try an echo command instead of a PHP command to make sure that PHP is the culprit. – Eric Hammond Nov 08 '11 at 21:32
  • 2
    In addition to sending stdout to the log file, also send stderr so you get error messages: ...updateIp.php >> /home/ubuntu/crontab.log 2>&1 – Eric Hammond Nov 08 '11 at 21:33
  • I've edited your question to clarify that you are using AMIs built and published by Canonical. I list their Ubuntu AMI ids at the top of http://Alestic.com but I have migrated the publishing responsibility to Canonical and they have resources dedicated to supporting this process. – Eric Hammond Nov 08 '11 at 21:34

2 Answers2

3

Check stat cron is running

status cron 
cron start/running, process 1380

or

ps aux | grep cron
root      1380  0.0  0.0   2092   876 ?        Ss   Nov03   0:02 cron

If it's running or not then have a look in /var/log/syslog and see if there are any relevant messages.

grep CRON /var/log/syslog
Nov  9 11:18:29 iain-ubuntu cron[3509]: (CRON) STARTUP (fork ok)
Nov  9 11:18:29 iain-ubuntu cron[3509]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
user9517
  • 115,471
  • 20
  • 215
  • 297
  • I have checked to see that cron is running, and was elated to see my commands listed in the syslog file (right around the time they should be), but there wasn't much other information explaining why exactly the ip_address.txt file did not update itself. It simply claims the php script was run, and shows me the commands, but ip_address.txt is unchanged. – darkAsPitch Nov 09 '11 at 19:08
  • @darkAsPitch: If ip_address.txt is unchanged, this probably means that cron is working fine, but that your `updateIp.php` isn't working as expected. To test this, replace `updateIp.php` which something which simply prints to standard out. You should see the output in /home/ubuntu/crontab.log. Remember that cron runs with a minimal environment which is different then your typical commandline environment. – Stefan Lasiewski Nov 09 '11 at 19:26
  • for some reason I had to specify /usr/bin/php-cgi from the crontab file, when /usr/bin/php works normally. It not works. Thank you for all your help. – darkAsPitch Nov 28 '11 at 04:09
0

Most probably, the cron service is turned off

Farhan
  • 4,269
  • 11
  • 49
  • 80
  • cron was indeed running, but I had to specify php-cgi instead of php in the crontab area for some reason. Do you know why? – darkAsPitch Nov 09 '11 at 22:43