We help IT Professionals succeed at work.

CentOS crontab doesn't work

Daniele Brunengo
on
326 Views
Last Modified: 2017-03-30
Hello, I'm trying to understand why the heck my CentOS server won't run crontab as it should. All other crons run just fine, but I have setup the system crontab as shown below. It should run backup.sh at midnight, but it doesn't.

This is the job definition in the /etc/crontab file

0 0 * * * root /home/backup.sh

Open in new window


Here's part of today's logs:

Mar 23 23:00:01 srvdati CROND[17331]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:01:01 srvdati CROND[17337]: (root) CMD (run-parts /etc/cron.hourly)
Mar 23 23:01:01 srvdati run-parts(/etc/cron.hourly)[17337]: starting 0anacron
Mar 23 23:01:01 srvdati run-parts(/etc/cron.hourly)[17346]: finished 0anacron
Mar 23 23:01:01 srvdati run-parts(/etc/cron.hourly)[17337]: starting mcelog.cron
Mar 23 23:01:01 srvdati run-parts(/etc/cron.hourly)[17365]: finished mcelog.cron
Mar 23 23:10:01 srvdati CROND[17506]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:20:01 srvdati CROND[17651]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:30:01 srvdati CROND[17795]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:40:01 srvdati CROND[17941]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:50:01 srvdati CROND[18087]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 23 23:53:01 srvdati CROND[18095]: (root) CMD (/usr/lib64/sa/sa2 -A)
Mar 24 00:00:01 srvdati CROND[18240]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 00:01:01 srvdati CROND[18246]: (root) CMD (run-parts /etc/cron.hourly)
Mar 24 00:01:01 srvdati run-parts(/etc/cron.hourly)[18246]: starting 0anacron
Mar 24 00:01:01 srvdati anacron[18258]: Anacron started on 2017-03-24
Mar 24 00:01:01 srvdati anacron[18258]: Jobs will be executed sequentially
Mar 24 00:01:01 srvdati anacron[18258]: Normal exit (0 jobs run)
Mar 24 00:01:01 srvdati run-parts(/etc/cron.hourly)[18260]: finished 0anacron
Mar 24 00:01:01 srvdati run-parts(/etc/cron.hourly)[18246]: starting mcelog.cron
Mar 24 00:01:01 srvdati run-parts(/etc/cron.hourly)[18279]: finished mcelog.cron
Mar 24 00:10:01 srvdati CROND[18420]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 00:20:01 srvdati CROND[18564]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 00:30:01 srvdati CROND[18709]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 00:40:01 srvdati CROND[18855]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 00:50:01 srvdati CROND[19000]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:00:01 srvdati CROND[19142]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:01:01 srvdati CROND[19150]: (root) CMD (run-parts /etc/cron.hourly)
Mar 24 01:01:02 srvdati run-parts(/etc/cron.hourly)[19150]: starting 0anacron
Mar 24 01:01:02 srvdati anacron[19162]: Anacron started on 2017-03-24
Mar 24 01:01:02 srvdati anacron[19162]: Jobs will be executed sequentially
Mar 24 01:01:02 srvdati anacron[19162]: Normal exit (0 jobs run)
Mar 24 01:01:02 srvdati run-parts(/etc/cron.hourly)[19164]: finished 0anacron
Mar 24 01:01:02 srvdati run-parts(/etc/cron.hourly)[19150]: starting mcelog.cron
Mar 24 01:01:02 srvdati run-parts(/etc/cron.hourly)[19183]: finished mcelog.cron
Mar 24 01:10:01 srvdati CROND[19262]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:20:01 srvdati CROND[19407]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:30:01 srvdati CROND[19553]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:40:01 srvdati CROND[19698]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Mar 24 01:50:01 srvdati CROND[19843]: (root) CMD (/usr/lib64/sa/sa1 1 1)

Open in new window


I have no emails in the root mailbox either, don't know what else to check.
Comment
Watch Question

Top Expert 2015

Commented:
Do you need job to run at exact second? Maybe you can introduce backup in /etc/cron.daily/* setting good times for it in /etc/anacrontab

Is your script executable (+x), is it unwritable by others (go-w) and needs no console input?
You can add -x to crond_arguments in /etc/sysconfig/crond to have more logs on why it rejects script

Are all programs specified with full paths and full extra environment (cron does not parse various (.)*profile files)
Does the script start with #!... ? Is it /bin/bash?
You can add -x to most shells in that place to have them print all commands it runs.
Can you show the script?
Daniele BrunengoIT Consultant, Web Designer

Author

Commented:
The script works perfectly if I run it by hand, and doesn't need any user input.

Anyway I've tried for instance with this script:
#!/bin/bash
mail -s "PROVA" myemail@mydomain.com <<< 'TEST'

Open in new window


Adding -x to crond arguments resulted in crond not starting (unknown command).

Anyway, there is no reference anywhere to these unexecuted scripts.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Why do you gave root?
Try
0 0 * * * /home/backup.sh

Open in new window


List the permissions of /home/backup.sh
If you in the shell execute the script /home/backup.sh

You are using commands (mail) presuming that mail us in the path.
IMHO, scripts should inject messages directly into /usr/sbin/sendmail versus using email client ...
The direct injection provides the script creator ...........
Daniele BrunengoIT Consultant, Web Designer

Author

Commented:
Please don't focus on the script, no script is working with this method. The system is not even trying to load the script.

About root, isn't the syntax supposed to be like this:

*  *  *  *  * user-name command
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
In your posting of the log, there was no reference to the line you posted. In which crontab is the line? Are there other lines in there?
Mar 24 00:00:01 srvdati CROND[18240]: (root) CMD (/usr/lib64/sa/sa1 1 1)

I do not see a reference  to cron trying at 0:0 to run this script suggests ..........
While elevating your rights, run crontab -e us this where the command is.
Or is it in your local user (non root) crontab.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Usually to run a command as specific user the su -u user -c command ....
Daniele BrunengoIT Consultant, Web Designer

Author

Commented:
crontab -e shows you the user crontab, which is empty. This is the system crontab, located in /etc/crontab.

There is no reference to the script and that's exactly the problem. The system isn't even trying to run the script and I don't know why.
Nick UpsonPrincipal Operations Engineer
CERTIFIED EXPERT

Commented:
I'd expect to find it in /etc/cron.d not /etc/crontab
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
There is cron, Anacron, it is kit clear that your reference is correct.


if you need to run it daily, add it to root's crontab or to the Anacron cron.daily.
IT Consultant, Web Designer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Daniele BrunengoIT Consultant, Web Designer

Author

Commented:
So this is the correct code at the end of the file:

0 0 * * * root /home/backup.sh
(and then a line break)

Open in new window

CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
glad to see.
Daniele BrunengoIT Consultant, Web Designer

Author

Commented:
It was a simple mistake on my part.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.