Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

[Solved] Cron runs 2 times

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
solamour
l33t
l33t
User avatar
Posts: 749
Joined: Tue Dec 21, 2004 11:29 pm
Location: San Diego, CA

[Solved] Cron runs 2 times

  • Quote

Post by solamour » Tue May 29, 2018 5:47 pm

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

Code: Select all

/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: Select all

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: Select all

# 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.
Top
jagdpanther
l33t
l33t
Posts: 820
Joined: Sat Nov 22, 2003 2:26 pm

  • Quote

Post by jagdpanther » Wed May 30, 2018 6:05 pm

Solamour:

Code: Select all

/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: Select all

*/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.
Top
solamour
l33t
l33t
User avatar
Posts: 749
Joined: Tue Dec 21, 2004 11:29 pm
Location: San Diego, CA

  • Quote

Post by solamour » Thu May 31, 2018 9:23 pm

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

Code: Select all

/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: Select all

/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
Top
solamour
l33t
l33t
User avatar
Posts: 749
Joined: Tue Dec 21, 2004 11:29 pm
Location: San Diego, CA

  • Quote

Post by solamour » Tue Jul 03, 2018 4:07 pm

I'm using "sys-process/cronie", and I just happen to notice the following.

Code: Select all

# 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: Select all

# 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
Top
solamour
l33t
l33t
User avatar
Posts: 749
Joined: Tue Dec 21, 2004 11:29 pm
Location: San Diego, CA

  • Quote

Post by solamour » Tue Jul 10, 2018 11:06 pm

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
Top
Post Reply

5 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic