Why is this cron entry executed twice?

前端 未结 12 978
栀梦
栀梦 2020-12-10 01:39
*/5 * * * * my command

This entry works but every 5 minutes it gets executed twice, why?

In /var/log/cron it shows:

         


        
相关标签:
12条回答
  • 2020-12-10 02:26

    I've recently migrated from vixie-cron to cronie and noticed my root crontab was a duplicate of my user crontab file.

    Execute/run "crontab -e", both as a user and as root, and examine the files to ensure duplicate commands are not being issued.

    As root:

    crontab -e

    As user: $ crontab -e

    If the files are significantly similar, might be best to insert a "# TEST" comment within the unwanted crontab contents to insure no symlinks or other anomalies exist prior to deleting the contents of the crontab file.

    0 讨论(0)
  • 2020-12-10 02:30

    If it's a command for an application you installed, maybe it already added the same entry to /etc/crontab or /etc/cron.d/<something>.

    0 讨论(0)
  • 2020-12-10 02:40

    Nothing in the description gives reason for it to be executed twice. Look elsewhere.

    • Do two users call it?
    • Is it entered twice?
    • Does it call itself?
    • Does it set in motion conditions for repetition?

    If it's a shell script you're executing, have it append whoami and date to a log file. You should be able to dig up the reason.

    UPDATE

    Type ps -A | grep crond, make sure crond isn't running twice.

    0 讨论(0)
  • 2020-12-10 02:40

    I thought cron was launching my bash script twice, but I was wrong. I thought I'd share my experience for (hopefully) the benefit of others. It had me scratching my head for a bit ...

    At the moment of being launched by cron, 'ps aux' output changed from showing 0 instances of my script running to two instances, or so it seems at first blush:

    kdeen    1797750  0.0  0.0   2608   600 ?        Ss   15:52   0:00 /bin/sh -c /home/kdeen/bin/once-a-day-local.sh
    kdeen    1797751  0.0  0.0  19520  3488 ?        S    15:52   0:00 /bin/bash /home/kdeen/bin/once-a-day-local.sh
    

    But look a little closer and I see one instance is /bin/sh -c and the other is /bin/bash. This is correct behavior. My script starts with "#!/bin/bash" but cron ALWAYS runs stuff with /bin/sh. So there's an 'sh' launcher process and then there's my bash script. All good.

    0 讨论(0)
  • 2020-12-10 02:42

    I had the same problem once, in my case was that I initialize the cron service twice by mistake. After I stopped cron # /etc/init.d/crond stop and started it again # /etc/init.d/crond start, it worked perfectly.

    I hope this can help anybody.

    0 讨论(0)
  • 2020-12-10 02:45

    Running ps -A | grep cron, killing all jobs didnt't help in my case. Problem was after killing all cron jobs and starting again with only one cron daemon I would get two cron jobs started from the same parent cron PPID - one with /bin/bash - the other one with /bin/sh

    Solution was to reboot server.

    This happened on several occasions, different OSs - centos 6 and redhat 7. Usually after online OS upgrade without reboot.

    As someone said - probably some different context.

    I saw one article on the net with same processes one with /bin/bash other one with /bin/sh at exactly same time - i thought yeeee - this is my case - but no, guy didn't even give a thought what is the root cause for such strange behavior, just started writing some script logic to make second process exit which is not really a solution.

    BTW ps -A | grep cron will also list all cron childs - normal cron jobs, more cron processes doesn't mean it is more cron daemons, might be only one daemon and others are childs.

    ps -ef | grep cron on the other hand lists only one - why? Because ps -ef lists childs as CROND - to get them all do ps -ef | grep -i cron

    0 讨论(0)
提交回复
热议问题