CRON does not execute

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read this

CRON does not execute

Postby PatrickLatour on Sun Apr 22, 2012 8:09 am

Hello all,
here is my problem: I have a cronjob that does not execute when scheduling. I went to a couple of trouble shooting action:

1-) grep cron Result:1463 so cron deamon is running
2-)crontab -l Result below:

patrick@patrick-pc ~ $ crontab -l
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
MAILTO="****.****.****@gmail.com"
54 7 * * 0,6 /home/patrick/Scripts/script01
55 7 * * 0,6 /home/patrick/Scripts/script02
56 7 * * 0,6 /home/patrick/Scripts/script03
#

3-) Notice the empty remark at the end, I read somewhere that it takes an empty line at the end.

So my questions are: What am I doing wrong ? and Where in the logs can I see if cron returns an error ?

Thanks all
Some peoples are like a Slinky, totally useless but they always make you smile when you push them in the stairs.
Proudly using LMDE and nothing else. HP Pavillon Quad Core 4GB RAM
http://www.linuxmint.com/img/signatures/donors/4093.png
User avatar
PatrickLatour
Level 1
Level 1
 
Posts: 6
Joined: Wed Jan 04, 2012 1:21 pm
Location: Montreal, Quebec, Canada

Linux Mint is funded by ads and donations.
 

Re: CRON does not execute

Postby karlchen on Sun Apr 22, 2012 4:00 pm

Hello, PatrickLatour.
I have a cronjob that does not execute when scheduling.

If my counting is right, then you scheduled 3 separate scripts, not just 1. :wink:
How do you know they are not executed?
Have you located the relevant entries in the logfile /var/log/syslog? What does syslog tell you about your 3 scripts?
Maybe they are launched by cron as designed, but fail to complete due to an error?
Have you added some internal logging functionality to your scripts so that they log their own actions to dedicated logfiles perhaps?
When scheduling the 3 scripts to run each Saturday and Sunday morning at 7:54, 7:55 and 7:56 respectively, have you kept in mind that they will not be run in case the machine is not switched on at the specified time? (This thought will be irrelvant provided your machine runs 24 hours a day.)

3-) Notice the empty remark at the end, I read somewhere that it takes an empty line at the end.
As far as I know cron does not care about comment lines. There should be no need of having a trailing comment line. But maybe a particular cron version had a bug which made it ignore the last crontab line unless it was ended by a proper linefeed?

Where in the logs can I see if cron returns an error ?
/var/log/syslog should hold entries about all cron activities.

A very simple way of making your 3 scripts create their own logfiles which should hold all error messages as well would be changing your crontab lines look like this:
Code: Select all
54 7 * * 0,6 /home/patrick/Scripts/script01 > /home/patrick/Scripts/script01.log 2>&1
55 7 * * 0,6 /home/patrick/Scripts/script02 > /home/patrick/Scripts/script02.log 2>&1
56 7 * * 0,6 /home/patrick/Scripts/script03 > /home/patrick/Scripts/script03.log 2>&1


Kind regards,
Karl
User avatar
karlchen
Level 11
Level 11
 
Posts: 3772
Joined: Sat Dec 31, 2011 7:21 am

Re: CRON does not execute

Postby PatrickLatour on Mon Apr 23, 2012 4:32 pm

Thanks Karl, I will correct the scripts to make them generate a log and will see from there. The day and time the script should execute is not a problem since my machine is "ON" 24 hours a day. Another point I am thinking about some researches is probably an error generated du the PATH variables. Will have to investigate that side, depending of what I will see in the logs.

Regards,
Some peoples are like a Slinky, totally useless but they always make you smile when you push them in the stairs.
Proudly using LMDE and nothing else. HP Pavillon Quad Core 4GB RAM
http://www.linuxmint.com/img/signatures/donors/4093.png
User avatar
PatrickLatour
Level 1
Level 1
 
Posts: 6
Joined: Wed Jan 04, 2012 1:21 pm
Location: Montreal, Quebec, Canada

Re: CRON does not execute

Postby karlchen on Tue Apr 24, 2012 6:19 pm

Hello, PatrickLatour.

Forgot to mention:
It may be a good idea to source the user's .bashrc file in any script which is executed by cron in order to make sure the proper user environment gets loaded. At least this is the way how we do it on HP-UX. Maybe there is a more elegant way on Linux . If so, I have failed to find out which way. :( Guess I should study the man pages one more time.

Cheers,
Karl
User avatar
karlchen
Level 11
Level 11
 
Posts: 3772
Joined: Sat Dec 31, 2011 7:21 am

Re: CRON does not execute

Postby DrHu on Tue Apr 24, 2012 7:20 pm

How about the internet connection, always running
and about the MAILTO variable, correct entry or not ?
http://service.futurequest.net/index.ph ... le/View/23
    Can you use * for that element, I know you can for dates..
User avatar
DrHu
Level 16
Level 16
 
Posts: 6887
Joined: Wed Jun 17, 2009 8:20 pm

Re: CRON does not execute

Postby P_A_R on Sat May 19, 2012 10:50 am

I have the same problem.
In /var/log/syslog.1 I find
May 19 04:00:01 par-GF7100-7050PVT-M3 CRON[21142]: (root) CMD ( run-parts /etc/cron.backup)
May 19 04:00:01 par-GF7100-7050PVT-M3 CRON[21141]: (CRON) error (grandchild #21142 failed with exit status 1)
May 19 04:00:01 par-GF7100-7050PVT-M3 CRON[21141]: (root) MAIL (mailed 1 byte of output; but got status 0x00ff, #012)
May 19 04:01:01 par-GF7100-7050PVT-M3 CRON[21194]: (root) CMD ( run-parts /etc/cron.backup)
May 19 04:01:01 par-GF7100-7050PVT-M3 CRON[21193]: (CRON) error (grandchild #21194 failed with exit status 1)
May 19 04:01:01 par-GF7100-7050PVT-M3 CRON[21193]: (root) MAIL (mailed 1 byte of output; but got status 0x00ff

I have created a directroy called cron.backup in which I have a backup routine (and I plan to add more routines here) to be executed every night at 04:00. This worked like a charm in my old distro (Fedora 9), but in Mint 12 it does not fly.

Crontab setup:
.....
.....
02 4 * * * root run-parts /etc/cron.backup

In cron.backup (ls -l):
-rwx--x--x 1 root root 98 2012-05-08 12:00 ext-backup

ext-backup contains
date > /media/Expansion*Drive/par/ext-backuptime.log
cp /home/par/* -r /media/Expansion*Drive/par

and this has worked well until now.
P_A_R
Level 1
Level 1
 
Posts: 9
Joined: Tue Mar 20, 2012 12:27 pm


Return to Other Topics

Who is online

Users browsing this forum: No registered users and 1 guest