Scripts in cron.d suddenly not working

Asked by Paladine

I dunno what is going on here, but I recently added a script to run every 10 minutes to /etc/cron.d

It was working fine for a week but then it suddenly stopped working (and I made no changes to the script at any point).

The script looks like this:

0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/blog/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache2/blog.paladine.org.uk-access.log ] && /usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update >/dev/null

But when I try and run the script to test it I get the following error:

paladine@mail:/etc/cron.d$ sudo ./awstats
./awstats: line 1: 0,10,20,30,40,50: command not found

Yet if I run:
sudo /usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update

It works fine.

I can't figure out why cron has suddenly stopped working with scripts in /etc/cron.d no matter what script I try to add there, it fails with "command not found" it just makes no sense.

Any help appreciated.

Paladine

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu cron Edit question
Assignee:
No assignee Edit question
Solved by:
Paladine
Solved:
Last query:
Last reply:
Revision history for this message
Cesare Tirabassi (norsetto) said :
#1

You can't execute a crontab like that, its not a shell script.
Did you manually add crontab files?
What is the output of crontab -l?

Revision history for this message
Paladine (paladine) said :
#2

Nope I added the script directly to /etc/cron.d/ as the installation guide for awstats tells you. It worked fine for a week and then just stopped working and I don't understand why.

I just checked the mail from syslog to www-data and I had an error about /bin/sh regarding -x so I have edited the script to remove everything apart from

/usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update >/dev/null

I will know if that fixes it in 4 minutes, but even if it does, why did the script work for an entire week before suddenly throwing errors? Makes no sense to me.

Revision history for this message
Bhavani Shankar (bhavi) said :
#3

Yes crontab file has a specific method for execution Its not a kind of shell script. A crontab is a simple text file that holds a list of commands that are to be run at specified times. These commands, and their related run times, are controlled by the cron daemon and are executed in the system's background. Refer These articles:
https://help.ubuntu.com/community/CronHowto
and
http://blog.lxpages.com/2007/03/27/scheduling-for-absolute-beginners/
and please paste the output of crontab-l...

Revision history for this message
Paladine (paladine) said :
#4

Yeah I read the CronHowTo already and I have been using cron for about 15 years so I don't know what is going on here. There is no output for crontab -l for either root, www-data or paladine (my username).

Also the errors I had in email were for a test script I tried this morning where I made a syntax error so altering the awstats script to just use

0,10,20,30,40,50 * * * * www-data /usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update >/dev/null

Has made no difference.

Here is the output from syslog:

Aug 6 10:40:01 mail /USR/SBIN/CRON[22483]: (www-data) CMD (/usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update >/dev/null)

It seems to have run according to syslog (which is what syslog has been reporting all along) but the stats have not updated and I have no email from syslog for www-data giving any errors for the 10:40 job

It's driving me batty.

Revision history for this message
Paladine (paladine) said :
#5

If you have a look here:

http://blog.paladine.org.uk/cgi-bin/awstats.pl?month=07&year=2007&output=main&config=blog.paladine.org.uk&framename=index

You can see when the script first failed (July 28th) I ran it manually on July 29th and July 30th, it failed again on July 31st and Aug 1st-Aug 4th and I ran it manually again on Aug 5th and Aug 6th (today)

Revision history for this message
Cesare Tirabassi (norsetto) said :
#6

Can you check in your logs what updates were made on the 28th (or just before)?
Check also what you have in /var/spool/cron/crontabs.

Manually adding the script is not the right way to do it anyhow.
Why not adding it with crontab -e (or sudo crontab -e if it is a system crontab)?

Revision history for this message
Cesare Tirabassi (norsetto) said :
#7

Was the pie good?

Revision history for this message
Paladine (paladine) said :
#8

Haven't eaten the pie yet it is for lunch, but I am looking forward to it.

I just tried running:

/usr/lib/cgi-bin/blog/awstats.pl -config=awstats -update

whilst su'd to www-data and I got a permissions error on reading the log file. So I have just edited the cron.d/ script again and changed user from www-data to root. Will know in 3 minutes if that fixes it.

Revision history for this message
Paladine (paladine) said :
#9

OK it is running fine as root, I still don't get why it worked for 12 days and then started to fail. I can only guess that something updated at some point without me realising and changed some permissions. It should be safe enough to leave it running as root user so I will just leave it like that. Thanks for the help.

Revision history for this message
straygrey (alf-stockton) said :
#10

I am running Ubuntu 7.10 at www.stockton.co.za and have various scripts in /etc/cron.daily. These scripts do not appear to ever run.
One of the scripts looks like:-
#!/bin/sh
echo "Vital signs for" $(uname -n) "on "`date +%Y-%m-%d` > /home/alf/vs.txt
printf "\n" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
echo "| Drive Utilisation |" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
/bin/df >> /home/alf/vs.txt
printf "\n" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
echo "| Free Memory |" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
/usr/bin/free >> /home/alf/vs.txt
printf "\n" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
echo "| Uptime and Load |" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
echo $(uptime) >> /home/alf/vs.txt
echo The current users are $(who -s) >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
echo "| Google search |" >> /home/alf/vs.txt
echo "+-------------------+" >> /home/alf/vs.txt
/home/alf/google_search.sh >> /home/alf/vs.txt
cat /home/alf/vs.txt | mail -s "Vital Signs" <email address hidden>

and is executable but never appears to run.

Revision history for this message
Garry Parker (parker13) said :
#11

Not sure why your script isn't running, but here's a tip - you don't need to redirect every line to the file. If you enclose the commands in parenthesis then you can redirect all of the output to a file. e.g.:

#!/bin/sh
{
  echo "hello"
  echo "world"
} > /tmp/vs.txt

It just makes it a lot more readable.