Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On Ubuntu 11.10 (Oneiric Ocelot), my cron job run fine if I use the default

* * * * *

But if I want it to run at 17 hrs or any other time, it never runs. My settings are:

00 17 * * * wget http://www.abc.com/a.php

I also tried:

00 17 * * * root wget http://www.abc.com/a.php

I also tried specifying the path. There is a carriage return, and I'm logged in as root

Here is my complete crontab:

TZ=Australia/Sydney
22 7 * * * /usr/bin/wget http://www.abc.com/a.php
22 7 * * * /bin/date >> /tmp/date.txt

----the out put is as follws:

root@Scrunch:~# sudo crontab -l -u root
55 12 * * * date >>/tmp/crontest.txt





root@Scrunch:~# 

Why is the terminal displaying so many blank lines after outputting the crontab entries? do you suspect unnecessary carriage lines are given....And i have not given any entries any other cron spaces like .d,/daily eyc.,

share|improve this question

2 Answers 2

Use only one zero for the minute. It is also usually a good idea when creating cron jobs to use the full path of the command you are using. This is because cron jobs run in a special very limited shell environment, and your path may differ from what you use when logged in. If you don't know it, you can easily find it out with the which command:

which wget

Another thing, the last command root wget http://www.abc.com/a.php, is incorrect. root is not a valid command. I am guessing you meant to use sudo. This would be unnecessary if you are running the cron job as root, i.e.

sudo crontab -e
share|improve this answer
    
I only meant to add it to your question, not remove everything else. :-) Anyways, I think you need to remove the TZ=Australia/Sydney It shouldn't be necessary, as cron will run as whatever timezone the user is in anyway, and I think it may be causing the issue. –  reverendj1 May 29 '12 at 21:33
    
I'm really stumped, and without being able to just chat, this is proving to be a tough nut to crack. It has to be something really really simple. –  reverendj1 May 29 '12 at 21:45

if your cron job definition is invalid, this will be logged in /var/log/syslog. What I usually do is set the cron job to run 2 minutes from now, then tail -f /var/log/syslog and ensure that things run as expected.

If there are no errors logged in /var/log/syslog, but the command failed to run (or even it it succeeded), cron will email you the console output from the command run. If you're not receiving these emails (you can look in /var/spool/mail/root) then something else is going wrong. I notice you're not using the -Q switch to wget, so you should get email every time it runs.

Finally, the 6th field (where you put root in your third example) is valid only on the system crontab file (/etc/crontab or any of the /etc/cron.{d,hourly,daily,weekly,monthly} fragment directories. It's not valid on a user's crontab (which seems to be what you're using).

I did the following to validate that things work correctly in principle, you may want to follow this procedure to at least ensure we're doing things the same way:

  1. Become root (I usually do sudo -i). This is because you're saying you want to do this as root.
  2. crontab -e. You'll be put in an editor to edit the crontab file.
  3. Add the following line (adjust to local time so it runs in the next 3 minutes. Give yourself some time to finish typing and save the file).

    05 10 * * * date >>/tmp/crontest.txt

  4. Delete or comment out everything else in the crontab file.
  5. Save the file and exit the editor
  6. Confirm that the cron was correctly installed by running crontab -l
  7. Wait until the configured time
  8. confirm a line like this appears in /var/log/syslog:

May 30 10:05:01 snowflake CRON[4170]: (root) CMD (date >>/tmp/crontest.txt)

Finally confirm that /tmp/crontest.txt was created and contains the scheduled time/date.

Cron has been in Unix/Linux for ages, it's tested and reliable, so what you're experiencing is not a bug, and you seem to be doing things right, so there must be something else that's affecting its functioning correctly. Hopefully we can determine what it is with some diagnostic procedures :)

share|improve this answer
    
no errors in syslog, but command fails to run, but i see mail in /var/spool/mail/root. but this is only for * * * * *. it is not still working for any custom time. just now i checked for our local Sydney Time 6.36 AM | 36 6 * * * /usr/bin/wget abc.com/a.php. oops it failed again –  Raghu May 29 '12 at 20:36
    
What happens if you remove the TZ variable? Do you see anything in /var/log/syslog? You should see something like this: CRON[XXXXX]: (root) CMD ( /usr/bin/wget abc.com/a.php) if you don't see it, it means something else is wrong. FWIW, your cron line itself (36 6 * * * whatever-command) is correct, so the problem must lie elsewhere. –  roadmr May 29 '12 at 23:49
    
TZ is actually removed, my system is anyhow configured to New South Wales/Sydney Time Zone. Point is except for default ***** cron is not running. one more observation if i use */x kind of configuration then it is working. please suggest me syntax for running a cron job for times: 12 noon and 5 PM –  Raghu May 30 '12 at 9:27
    
I'll update my answer because what I tried is a bit too long for a comment. –  roadmr May 30 '12 at 14:06
    
OK, on the edit you attempted on my answer we see this: May 31 00:55:01 Scrunch cron[27182]: (index.html) ORPHAN (no passwd entry). This means a malformed crontab entry where cron thinks that index.html is the user. I suggest you double-check your syntax, or update your question with output of sudo crontab -l -u root so we can see all the entries that are there and try to fix them. Also, this may be in one of the system-wide crontab files, if you have modified any of /etc/crontab/, /etc/crontab.d/*, or /etc/crontab.{hourly,daily,weekly,monthly} please double-check them as well. –  roadmr May 30 '12 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.