LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 07-17-2015, 04:17 AM   #1
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Rep: Reputation: 1
I am getting 2 occurrences of my backup.cron


I am running CentOS release 6.6 (Final)
I have a cron daily running:
Code:
02 4 * * * root run-parts /etc/cron.daily
I have a backup cron running which sends me an email every day to inform me that it has run, but I get 2 occurrences of it:
Quote:
root 04:02 ASHBARN fileserver backup run
root 04:02 ASHBARN fileserver backup run
If I change the backup.cron to chmod 644, it stops working altogether. I don't get any email notification at all.
Can anybody advise me why this is, and where the second occurrence is running from.

Thank you

Last edited by countrydj; 07-17-2015 at 04:18 AM.
 
Old 07-17-2015, 05:48 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,696

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
It depends on how your computer is configured but by default CentOS 5 runs cron.daily at 4:02 as posted but CentOS 6 uses anacron (/etc/anacrontab). Is backup.cron something you created yourself?
 
Old 07-17-2015, 05:50 AM   #3
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Further to my previous post, here is some relevant information from my log file:
Quote:
Jul 17 04:02:01 ashbarn run-parts(/etc/cron.daily)[15466]: starting backup.cron
Jul 17 04:02:01 ashbarn run-parts(/etc/cron.daily)[15467]: starting backup.cron
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15508]: finished backup.cron
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting cups
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15517]: finished cups
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting logrotate
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15525]: finished logrotate
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting makewhatis.cron
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15608]: finished backup.cron
Hopefully this may help in finding the answer.
As far as I know, all the cron jobs run from /etc/crontab
Is there anywhere else where cron jobs can run from ??

Cheers,
 
Old 07-17-2015, 06:02 AM   #4
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi Michealk..
Thanks for taking the time to reply.
Quote:
It depends on how your computer is configured but by default CentOS 5 runs cron.daily at 4:02 as posted but CentOS 6 uses anacron (/etc/anacrontab). Is backup.cron something you created yourself?
I don't have /etc/anacrontab on my computer, so the problem isn't that.
YES. backup.cron is created by me.
Here it is:
Code:
nice rsync -au --delete /etc /backup
nice rsync -au --delete /home /backup
nice rsync -au --delete /var --exclude 'named/chroot/proc' /backup
nice rsync -u /* /backup
df | /bin/mail -s "ASHBARN fileserver backup run" jc@ukzone.com
Before I saw your reply, I posted some info from my log files, which is posted just below yor answer.

Regards,
 
Old 07-17-2015, 06:34 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,696

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Not sure. I assume your getting only one email notification.
 
Old 07-17-2015, 07:54 AM   #6
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
No. I'm getting 2 email notifications:
Quote:
root 04:02 ASHBARN fileserver backup run
root 04:02 ASHBARN fileserver backup run
hth
 
Old 07-17-2015, 12:08 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by countrydj View Post
I don't have /etc/anacrontab on my computer, so the problem isn't that.
Is that because you removed it? anacron is installed by default in CentOS 6, and the cron daemon has dependencies on it.

Look in /etc/cron.d/ and see of some file in there is running anything that would also start jobs in /etc/cron.daily/ . Among other things, the default /etc/cron.d/0hourly will try to run jobs in /etc/cron.hourly, and there the /etc/cron.hourly/0anacron will try to start anacron, and I don't know what that's going to do in the absence of the /etc/anacrontab config file.
 
Old 07-17-2015, 12:29 PM   #8
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi rknichols
Thank you for your input.
Quote:
Is that because you removed it? anacron is installed by default in CentOS 6, and the cron daemon has dependencies on it.
No. I haven,t removed it. In fact it is a relatively new installation.
I have just run yum install -y anacron and I now have anacrontab.
I will let it run overnight and see what happens

I have checked /etc/cron.d/0hourly and it just wants to run 01 * * * * root run-parts /etc/cron.hourly

Thanks for your advice.
 
Old 07-17-2015, 03:33 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I wouldn't expect that installing anacron would help the situation -- might make it worse. I was just surprised that it wasn't already installed. I subsequently dug around and found the "cronie-noanacron" package, which would give you just the traditional cron behavior and does not have anacron as a dependency.

Have you looked in /var/log/cron for some clue as to how the two jobs were getting started?
 
Old 07-17-2015, 04:02 PM   #10
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Here is the installation of yum install -y anacron
Code:
[root@ashbarn c]# locate anacrontab
[root@ashbarn c]# yum install -y anacron
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror.mhd.uk.as44574.net
 * extras: centos.openitc.uk
 * updates: mirror.mhd.uk.as44574.net
Resolving Dependencies
--> Running transaction check
---> Package cronie-anacron.x86_64 0:1.4.4-12.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                             Arch                        Version                            Repository                 Size
====================================================================================================================================
Installing:
 cronie-anacron                      x86_64                      1.4.4-12.el6                       base                       30 k

Transaction Summary
====================================================================================================================================
Install       1 Package(s)

Total download size: 30 k
Installed size: 43 k
Downloading Packages:
cronie-anacron-1.4.4-12.el6.x86_64.rpm                                                                       |  30 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : cronie-anacron-1.4.4-12.el6.x86_64                                                                               1/1 
  Verifying  : cronie-anacron-1.4.4-12.el6.x86_64                                                                               1/1 

Installed:
  cronie-anacron.x86_64 0:1.4.4-12.el6                                                                                              

Complete!
Please note that I did a locate anacrontab, prior to running yum, and it turned up nothing.

Quote:
Have you looked in /var/log/cron for some clue as to how the two jobs were getting started?
I did check the log files but couldn't see anything that showed where backup.cron was being started. I posted the logs above.
 
Old 07-17-2015, 04:19 PM   #11
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
I've just had another look at the log files and seen something that may give a clue to why...
Code:
Jul 17 04:02:01 ashbarn CROND[15466]: (root) CMD (run-parts /etc/cron.daily)     
Jul 17 04:02:01 ashbarn CROND[15465]: (root) CMD ([ ! -f /etc/cron.hourly/0anacron ] && run-parts /etc/cron.daily)
Jul 17 04:02:01 ashbarn run-parts(/etc/cron.daily)[15466]: starting backup.cron 
Jul 17 04:02:01 ashbarn run-parts(/etc/cron.daily)[15467]: starting backup.cron 
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15508]: finished backup.cron  
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting cups         
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15517]: finished cups         
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting logrotate   
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15525]: finished logrotate   
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15466]: starting makewhatis.cron
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15608]: finished backup.cron 
Jul 17 04:02:48 ashbarn run-parts(/etc/cron.daily)[15467]: starting cups
I don't understand what all this code means, but here is /etc/cron.hourly/0anacron
Code:
#!/bin/bash
# Skip excecution unless the date has changed from the previous run
if test -r /var/spool/anacron/cron.daily; then
    day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
    exit 0;
fi

# Skip excecution unless AC powered
if test -x /usr/bin/on_ac_power; then
    /usr/bin/on_ac_power &> /dev/null
    if test $? -eq 1; then
    exit 0
    fi
fi
/usr/sbin/anacron -s
Hopefully you will understand this code and be able to tell me if this is what is starting the second backup.cron.

Cheers,
 
Old 07-17-2015, 07:22 PM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
OK, I downloaded the cronie-noanacron RPM and took a look at what it contains. I see a file /etc/cron.d/dailyjobs that contains
Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
02 4 * * * root [ ! -f /etc/cron.hourly/0anacron ] && run-parts /etc/cron.daily
22 4 * * 0 root [ ! -f /etc/cron.hourly/0anacron ] && run-parts /etc/cron.weekly
42 4 1 * * root [ ! -f /etc/cron.hourly/0anacron ] && run-parts /etc/cron.monthly
Are you also running cron.daily from somewhere else? Your original post did not say where you had that crontab entry, and anyway the one you showed is not the same as the entry in /etc/cron.d/dailyjobs.

If you're going to use anacron you should uninstall cronie-noanacron and replace it with cronie-anacron.

Last edited by rknichols; 07-17-2015 at 07:23 PM.
 
Old 07-20-2015, 06:26 AM   #13
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi rknichols...
Thank you for the trouble that you are going to to try and help me.
I have been testing various combinations, without much success.
However, the computer that is causing some concern is remote to me, and has closed down. I can't get into it to check anything.
I will continue when it is switched back on.
Meanwhile, can you tell me how I can run crontab contents, from crontab, as if it were in the normal course of events?
Regards,
 
Old 07-20-2015, 07:46 AM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by countrydj View Post
Meanwhile, can you tell me how I can run crontab contents, from crontab, as if it were in the normal course of events?
I'm not quite sure what you are asking. You can, for the most part, take the command portion of a crontab entry and give it to a shell run under the appropriate UID, but you can't easily duplicate the exact environment under which a cron job runs. The way I generally handle the manual triggering of a cron job is by temporarily modifying the crontab entry so that the job runs 2 minutes from now**, and then restore the original crontab afterward.

** The cron daemon will load the modified crontab when time rolls over to the next minute, but it does this after starting jobs for the current cycle. The first opportunity for running a new job will be the second time a minute rolls over. It's done that way so that you can have a cron job that modifies the crontab without causing an infinite loop.
 
Old 07-21-2015, 07:08 AM   #15
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi rknichols

Quote:
The way I generally handle the manual triggering of a cron job is by temporarily modifying the crontab entry so that the job runs 2 minutes from now**, and then restore the original crontab afterward.
Thanks for your suggestion. I didn't think of that, but it would do what I want it to do.
However, my client is now on holiday until the end of next week, and his server or router, is down.
I will resume when he gets back.
Regards,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job to backup prudens Linux - Newbie 16 08-10-2009 07:04 AM
i want to cron a backup script sneakyimp Linux - Software 4 03-25-2008 09:02 PM
Cron Backup TPupAZ Linux - Software 7 02-11-2005 07:49 AM
Can a backup be done with cron? sadly so Solaris / OpenSolaris 3 02-03-2005 01:28 AM
cron job - backup medamnit Linux - Newbie 4 05-24-2002 03:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 01:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration