I have a problem with executing crontab jobs. I guess I have everything configured properly but when i put:*/2 * * * * /var/www/site/executescript.sh in crontab -e My script is not being executed at all.. Only thing i get in cron.log is:
Feb 15 10:22:35 server crontab[2222]: (root) BEGIN EDIT (root)
Feb 15 10:22:45 server crontab[2222]: (root) REPLACE (root)
Feb 15 10:22:45 server crontab[2222]: (root) END EDIT (root)
Feb 15 10:26:24 server crontab[2329]: (root) BEGIN EDIT (root)
Feb 15 10:27:17 server crontab[2329]: (root) REPLACE (root)
Feb 15 10:27:17 server crontab[2329]: (root) END EDIT (root)
Feb 15 10:29:34 server crontab[2415]: (root) BEGIN EDIT (root)
Feb 15 10:29:53 server crontab[2415]: (root) REPLACE (root)
Feb 15 10:29:53 server crontab[2415]: (root) END EDIT (root)
What mean that cron doesn't even try to execute my script. Do anyone knew what is this related to? Does it mean there is an error in my script ( i don't see one..) Is there a place where i can check more accurate cron logs?
Version of my cron is v5.0
You need to define the binary executing the script. Try with this:
*/2 * * * * /bin/sh /var/www/site/executescript.sh in
Related
I put the following cron job in my root crontab under var/spool/cron
*/5 * * * * service php-fpm-5.5.11 restart
I see it called in the cron logs every 5 minutes, so I know it is being called, but it is not restarting php-fpm.
Question 1:
Is there a different way to restart services when calling them in cron?
What would be the correct way to call this restart?
Another question and the root of the problem is I have another call that runs every night that sometimes kills my website altogether because php-fpm is not restarting correctly:
/bin/kill -SIGUSR1 `cat /opt/pifpm/php-5.5.11/var/run/php-fpm.pid 2>/dev/null` 2>/dev/null || true
I get:
[12-Jul-2015 00:52:29] ERROR: An another FPM instance seems to already listen on /opt/pifpm/fpmsockets/5.5.11.sock
[12-Jul-2015 00:52:29] ERROR: FPM initialization failed
Question 2
Is there a better way to call the kill statement? For instance:
[ ! -f /opt/pifpm/php-5.5.11/var/run/php-fpm.pid ] || kill -USR2 `cat /opt/pifpm/php-5.5.11/var/run/php-fpm.pid`
This is an nginx and centos setup.
Here is a portion of the cron log:
Jul 15 12:15:01 insp CROND[7325]: (root) CMD (service php-fpm-5.5.11 restart)
Jul 15 12:15:01 insp CROND[7326]: (root) CMD (/usr/local/cpanel/scripts/recoverymgmt >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7327]: (root) CMD (/usr/local/cpanel/bin/dcpumon >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7332]: (root) CMD (/usr/local/cpanel/scripts/autorepair recoverymgmt >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7333]: (root) CMD (/usr/local/cpanel/bin/dbindex >/dev/null 2>&1)
Jul 15 12:16:53 insp /usr/bin/crontab[7530]: (root) BEGIN EDIT (root)
Jul 15 12:16:57 insp /usr/bin/crontab[7530]: (root) END EDIT (root)
Jul 15 12:20:01 insp CROND[7842]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 15 12:20:01 insp CROND[7845]: (root) CMD (/usr/local/cpanel/bin/dcpumon >/dev/null 2>&1)
Jul 15 12:20:01 insp CROND[7846]: (root) CMD (service php-fpm-5.5.11 restart)
Jul 15 12:20:01 insp CROND[7847]: (root) CMD (/usr/local/maldetect/maldet --mkpubpaths >> /dev/null 2>&1)
Answer to the Question number 1.
/etc/rc.d/init.d/php-fpm-5.5.11 restart is the correct path to use in cron.
The /etc/rc.d/init.d has most of the services in the directory including httpd
I have added an crontab like this:
*/15 * * * * /home/test/demo.py
However, it runs in two times. And, we can see that two logs are logged in /var/log/cron:
Jun 30 20:00:01 demo1.ops.dev CROND[29181]: (root) CMD (/home/test/a.py)
Jun 30 20:00:01 demo1.ops.dev CROND[29180]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 30 20:00:01 demo1.ops.dev CROND[29189]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 30 20:00:01 demo1.ops.dev CROND[29190]: (root) CMD (/home/test/a.py)
Answered by myself,
I restart the crond daemon. It can not resolve the problem,
I restart the machine. It can not be scheduled properly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
]# crontab -l
#ROOT CRONTAB test
#22 15 * * * root my_date=`date +\%Y-\%m-\%0e_\%H:\%M:\%S`; /usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb_${my_date}
53 13 * * * root /home/apache/tactic_custom_tools/backup.sh
]# more /home/apache/tactic_custom_tools/backup.sh
#!/bin/bash
/usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb/`date +\%Y-\%m-\%0e_\%H:\%M:\%S
It doesn't create anything under /home/apache/tactic_backup/postgresDb/
But when i run the script or command as root, it works and does the required. But via crontab it doesn't The crontab above is for root. Even in logs it shows that it ran(or so)
Jan 28 13:40:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:40:01 bjweb01 CROND[34555]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:40:01 bjweb01 CROND[34556]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)
Jan 28 13:46:47 bjweb01 crontab[34743]: (root) LIST (root)
Jan 28 13:49:53 bjweb01 crontab[34814]: (root) BEGIN EDIT (root)
Jan 28 13:50:01 bjweb01 CROND[34818]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) REPLACE (root)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) END EDIT (root)
Jan 28 13:53:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:53:01 bjweb01 CROND[34887]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)
Any idea what i am missing?
My documentation states that the mentioning of the user (root in this case) after the time restrictions is only valid in the system crontab which is stored at /etc/crontab.
You are showing us users' crontabs (shown with crontab -l) which differ in that aspect; the user must not be given there, even if the user is root.
Even though I set the PATH in /etc/crontab as
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/mailman/cron:/usr/lib/mailman/bin
commands found in /usr/lib/mailman/cron are still not found, Thus issuing a mail to root saying
/bin/sh: mailman: command not found
I've debugged the problem, setting up a cron entry
* * * * * /bin/echo "`/bin/date`: $PATH" >> /tmp/crontest.log 2>&1
using crontab -e which actually do write the PATH to /tmp/crontest.log, confirming that the path entered in /etc/crontab is not what cron think it should be.
Fri Feb 14 10:22:01 CET 2014: /usr/bin:/bin
I've also tried to solve it by re-start cron using (both) service crond restart and service crond stop;sleep 5;service crond start (which does the same, but to make absolutely certain that it has been restarted), but this doesn't change anything.
The /etc/crontab file is readable by everyone (permissions is 644 root root)
-rw-r--r-- 1 root root 500 10 feb 10:36 /etc/crontab
/var/log/cron does not show anything about the problem, just what's started and when I restarted the cron
grep -v CMD /var/log/cron
.
.
.
Feb 14 09:45:34 p1kitlst01l crond[12214]: (CRON) INFO (running with inotify support)
Feb 14 09:45:34 p1kitlst01l crond[12214]: (CRON) INFO (#reboot jobs will be run at computer's startup.)
Feb 14 09:48:07 p1kitlst01l crontab[12331]: (root) BEGIN EDIT (root)
Feb 14 09:48:45 p1kitlst01l crontab[12331]: (root) REPLACE (root)
Feb 14 09:48:45 p1kitlst01l crontab[12331]: (root) END EDIT (root)
Feb 14 09:49:01 p1kitlst01l crond[12214]: (root) RELOAD (/var/spool/cron/root)
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13010]: starting 0anacron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13027]: finished 0anacron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13010]: starting mcelog.cron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13039]: finished mcelog.cron
Feb 14 10:19:16 p1kitlst01l crontab[13840]: (root) BEGIN EDIT (root)
Feb 14 10:19:23 p1kitlst01l crontab[13840]: (root) END EDIT (root)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) STARTUP (1.4.4)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) INFO (running with inotify support)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) INFO (#reboot jobs will be run at computer's startup.)
Any suggestions to what I have to look in to?
Henrik
What I think is ,you have two ways to go (maybe others provide more).
1) set the absolute path for mailman in your script.
2) source the .profile, then run the script, such as:
0 1 * * * . ~/.profile; bash your_script.sh
I have the following crontab set up on a RHEL server ...
MAILTO=me#mydomain.com
*/2 * * * * wget --spider -q http://mydomain.com/cronjobs/importxml.php
As you can see this should run every 2 minutes, which it does, but it runs the command three times and I can't figure out why.
If I run
tail /var/log/cron
I get the following
Dec 12 13:56:01 msvsc02-g283nc crond[1431]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3224]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Dec 12 13:56:01 msvsc02-g283nc crond[2504]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3226]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Dec 12 13:56:01 msvsc02-g283nc crond[2472]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3228]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Can anyone shed any light on this?
You may have more than one cron process running in that server. This normally wont happen. But anyway confirm it with
ps aux | grep cron
You can stop it by,
/etc/init.d/cron stop
or
service cron stop
or use 'kill PID' ( not recommended ).
And to start use start - instead of stop in either of above two commands.