-1

I have one server that is triggering cron jobs correctly. This is the information on that server:

Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64)

crontab -l

* * * * * ( sleep 15 ; sudo /var/crons/NextQueueItemParallel.sh ) * * * * * ( sleep 45 ; sudo /var/crons/NextQueueItemParallel.sh )

The server that is not triggering the crons:

Ubuntu 12.04.4 LTS (GNU/Linux 3.16.5-x86_64-linode46 x86_64)

crontab -l

* * * * * ( sleep 30 ; sudo /var/crons/ParseLogs.sh )

I run the script manually, and it works. I verified the path is correct, and put this debugging code to see whether it was getting called:

echo 1 >> /var/crons/test php /var/www/crons/ParseLogFiles.php

I run it manually, and get a 1 appended to the end of test, but does not appear by itself. I have installed the right cron and anacron services, and tried the solutions outlined here:

php cron job not running | http://growingventuresolutions.com/blog/ubuntu-cron-isn-t-running-some-things-check.html | Cron Job Doesn't Run

EDIT 1:

I updated the crontab on the machine that currently is not working by issuing sudo crontab -e and the following line is now present (I verified by closing and re-opening):

* * * * * ( sleep 30 ; /var/crons/ParseLogs.sh ) (followed by a new line or two)

That file is comprised of the following:

echo 1 >> /var/crons/test php /var/www/crons/ParseLogFiles.php

I tail /var/crons/test (tail -f /var/crons/test) but do not see anything appended and the script does not run. When I run both of these manually (by copying the line), it does in fact run.

EDIT 2:

I did not have execute permissions, which is why it worked when I ran it manually but not on a cron. I issued the following command chmod +x /var/crons/ParseLogs.sh and it immediately began working. If you are viewing this and everything else seems to be working, check that! Thanks to everyone who helped!

Community
  • 1
  • 1
Nicholas Yost
  • 266
  • 6
  • 15
  • 2
    This is not really a programming problem. [unix.se] might be a better place to ask. Check their help centre. –  Nov 28 '14 at 03:41

2 Answers2

1

My guess would be that one of the servers has the requiretty config option for sudo enabled.

Assuming Ubuntu uses the same setup as Debian upstream, check /etc/sudoers or a file in /etc/sudoers.d/ directory for something like:

Defaults    requiretty

If you find it, remove it.

If you control the server, another option might be to move the cron tasks into either the root user's crontab or into the /etc/cron.d directory (the format for files in this directory specifies the user to run as)

Stephen
  • 18,597
  • 4
  • 32
  • 33
  • `cat /etc/sudoers | grep requiretty` returns no lines. I do have control over the server, but I'm obviously not a dedicated sysadmin. It was my understanding that the cron was ran as the user who added it, so I thought this would be the root users crontab. How do I know specifically what cron tab this is running as? – Nicholas Yost Nov 28 '14 at 05:08
  • 1
    If you use `crontab -e` it will edit the current user's crontab, yes. If you're doing that as root, you don't need to use sudo when calling the scripts. – Stephen Nov 28 '14 at 07:20
  • Sorry I took so long to respond! I'm updating the post with additional details. Thank you for answering me this much so far! – Nicholas Yost Dec 03 '14 at 01:53
0

I had to chmod +x /var/crons/ParseLogs.sh for the crontab to be able to execute it. Running it manually apparently bypassed this restriction since my cloud provider created the default account as root.

Nicholas Yost
  • 266
  • 6
  • 15