Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Cron runs 2 times
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 698
Location: San Diego, CA

PostPosted: Tue May 29, 2018 5:47 pm    Post subject: [Solved] Cron runs 2 times Reply with quote

I put a few scripts in "/etc/cron.daily/", so that they run every day.

Code:
/etc/crontab

59  *   *   *   *   root    rm -f /var/spool/cron/lastrun/cron.hourly
9   3   *   *   *   root    rm -f /var/spool/cron/lastrun/cron.daily
19  4   *   *   6   root    rm -f /var/spool/cron/lastrun/cron.weekly
29  5   1   *   *   root    rm -f /var/spool/cron/lastrun/cron.monthly
*/10 *  *   *   *   root    test -x /usr/sbin/run-crons && /usr/sbin/run-crons


The scripts run fine, but they are executed one more time a little later. For example, "/etc/cron.daily/b.py" ran at 03:10:12 and 03:37:40. Here are the timestamps for today.
Code:

b.py:   03:10:12, 03:37:40
cnh.py: 03:10:28, 03:38:24
c.py:   03:10:12, 03:39:12
h.py:   04:01:18, 05:18:11
r.py:   04:10:43, 05:29:53
v.py:   04:11:10, 05:30:49


And here are the log and the ps output, which suggest that there is only 1 instance of the cron.

Code:

# grep -i cron.daily /var/log/messages

May 29 03:00:02 gentoo anacron[1282]: Will run job `cron.daily' in 37 min.
May 29 03:01:02 gentoo anacron[2180]: Job `cron.daily' locked by another anacron - skipping
May 29 03:09:02 gentoo CROND[7407]: (root) CMD (   rm -f /var/spool/cron/lastrun/cron.daily)
May 29 03:10:01 gentoo run-crons[8290]: (root) CMD (/etc/cron.daily/b.py)
May 29 03:10:14 gentoo run-crons[8420]: (root) CMD (/etc/cron.daily/cnh.py)
May 29 03:10:29 gentoo run-crons[8533]: (root) CMD (/etc/cron.daily/c.py)
May 29 03:10:46 gentoo run-crons[8674]: (root) CMD (/etc/cron.daily/emerge-sync)
May 29 03:37:02 gentoo anacron[1282]: Job `cron.daily' started
May 29 04:00:05 gentoo anacron[29793]: Job `cron.daily' locked by another anacron - skipping
May 29 04:01:02 gentoo anacron[30570]: Job `cron.daily' locked by another anacron - skipping
May 29 04:01:06 gentoo run-crons[30702]: (root) CMD (/etc/cron.daily/h.py)
May 29 04:01:19 gentoo run-crons[30848]: (root) CMD (/etc/cron.daily/logrotate)
May 29 04:01:44 gentoo run-crons[31062]: (root) CMD (/etc/cron.daily/man-db)
May 29 04:10:35 gentoo run-crons[10894]: (root) CMD (/etc/cron.daily/r.py)
May 29 04:10:45 gentoo run-crons[11140]: (root) CMD (/etc/cron.daily/update-clock)
May 29 04:11:01 gentoo run-crons[11318]: (root) CMD (/etc/cron.daily/v.py)
May 29 05:00:02 gentoo anacron[7857]: Job `cron.daily' locked by another anacron - skipping
May 29 05:01:01 gentoo anacron[9366]: Job `cron.daily' locked by another anacron - skipping
May 29 05:30:52 gentoo anacron[1282]: Job `cron.daily' terminated (mailing output)

# ps axjf | grep -i [c]ron
    1  6385  6385  6385 ?           -1 Ss       0   0:02 /usr/sbin/crond


The system is very much under-powered (i.e. my phone is faster than this system), and it was quite busy the whole time, but I'm not sure that's the cause of the problem. I'd appreciate any suggestions on how to resolve the issue.
__
sol


Last edited by solamour on Thu May 31, 2018 9:23 pm; edited 2 times in total
Back to top
View user's profile Send private message
jagdpanther
l33t
l33t


Joined: 22 Nov 2003
Posts: 729

PostPosted: Wed May 30, 2018 6:05 pm    Post subject: Reply with quote

Solamour:


Code:
/etc/crontab

9   3   *   *   *   root    rm -f /var/spool/cron/lastrun/cron.daily


Clears the last run file. Your programs in cron.daily don't start running till the next time
Code:
*/15 * * * *     test -x /usr/sbin/run-crons && /usr/sbin/run-crons


runs. If you are using */15 * * * * as in the above example your cron.daily scripts should start at 0315.

I am having a trouble with double runs of scripts in cron.daily. I think I'll start a new message about that.
Back to top
View user's profile Send private message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 698
Location: San Diego, CA

PostPosted: Thu May 31, 2018 9:23 pm    Post subject: Reply with quote

I commented out everything in "/etc/crontab" and added "anacron", as described in Cron Wiki (https://wiki.gentoo.org/wiki/Cron#Installation).
Code:
/etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO="root"
HOME=/

*/10 *  *   *   *   root    /usr/sbin/anacron


And today, the scripts in "/etc/cron.daily" ran only once around 3AM. I also noticed that the scripts run based on the values specified in "/etc/anacrontab".
Code:

/etc/anacrontab

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly


Thanks everyone for taking time to share your knowledge and suggestions.
__
sol
Back to top
View user's profile Send private message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 698
Location: San Diego, CA

PostPosted: Tue Jul 03, 2018 4:07 pm    Post subject: Reply with quote

I'm using "sys-process/cronie", and I just happen to notice the following.
Code:
# emerge -pv anacron

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] sys-process/anacron-2.3-r2::gentoo  24 KiB
[blocks B      ] sys-process/anacron ("sys-process/anacron" is blocking sys-process/cronie-1.5.1-r1)

Total: 1 package (1 new), Size of downloads: 24 KiB
Conflict: 1 block (1 unsatisfied)

 * Error: The above package list contains packages which cannot be
 * installed at the same time on the same system.

  (sys-process/anacron-2.3-r2:0/0::gentoo, ebuild scheduled for merge) pulled in by
    anacron

  (sys-process/cronie-1.5.1-r1:0/0::gentoo, installed) pulled in by
    sys-process/cronie required by (virtual/cron-0-r1:0/0::gentoo, installed)


That doesn't seem to matter though, because cronie comes with anacron.
Code:
# eix cronie
[?] sys-process/cronie
     Available versions:  1.4.11-r1 ~1.4.11-r3 1.4.12 {anacron +inotify pam selinux}
     Installed versions:  1.5.1-r1(04:01:15 PM 05/22/2018)(anacron inotify pam -selinux)
     Homepage:            https://fedorahosted.org/cronie/wiki
     Description:         Cronie is a standard UNIX daemon cron based on the original vixie-cron

__
sol
Back to top
View user's profile Send private message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 698
Location: San Diego, CA

PostPosted: Tue Jul 10, 2018 11:06 pm    Post subject: Reply with quote

Here is something I wasn't aware of. Perhaps it might be useful for those who have the same problem.

As described in Cron Wiki (https://wiki.gentoo.org/wiki/Cron#Using_anacron), anacron is more useful for the systems that aren't running all the time, such as a laptop. When you turn on your laptop and if it missed a scheduled daily job (because the system was off), it starts the job. That marks the "last time it ran", so if you leave the laptop on until this time around tomorrow, it will run again this time around tomorrow.

On the other hand, if you want a job to run at a specific time of the day and the system is running pretty much all the time, it's better to stick with the regular cron. Might need to remove the execution flag of "/etc/cron.hourly/0anacron" if you are not using anacron.
__
sol
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum