CRON does not execute

Archived topics about LMDE 1 and LMDE 2
Locked
PatrickLatour

CRON does not execute

Post by PatrickLatour »

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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
karlchen
Level 23
Level 23
Posts: 18183
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: CRON does not execute

Post by karlchen »

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
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 762 days now.
Lifeline
PatrickLatour

Re: CRON does not execute

Post by PatrickLatour »

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,
User avatar
karlchen
Level 23
Level 23
Posts: 18183
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: CRON does not execute

Post by karlchen »

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
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 762 days now.
Lifeline
DrHu

Re: CRON does not execute

Post by DrHu »

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..
P_A_R

Re: CRON does not execute

Post by P_A_R »

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.
jamied_uk
Level 2
Level 2
Posts: 54
Joined: Fri Oct 22, 2010 3:37 am

Re: CRON does not execute

Post by jamied_uk »

im getting same sort of issue its not executing and do not know why :/


my code is a lil different but it should work

Code: Select all

*/5 * * * * php -f /var/www/html/cj/email1.php >/dev/null 2>&1

so maybe its the actual program or something any ideas hoiw to fix it for us both ( i didnt want to create a new post as this is relevant to both the original poster and myself but i could make a new post if needed!
r00t

Re: CRON does not execute

Post by r00t »

karlchen wrote:.... 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. ....
Just add the following to the start of the script:

Code: Select all

source ~/.bashrc
That will read the user's .bashrc file.

For example, I have the following in my .bashrc:

Code: Select all

export TEST="TEST"
Then I do this in the Terminal:

Code: Select all

r00t@rc ~ $ source ~/.bashrc; echo $TEST
TEST
r00t@rc ~ $ 
As you can see, it read (or sourced) my .bashrc file to set the $TEST variable and echo it back to me.
Locked

Return to “LMDE Archive”