0

GNU nano 2.0.9 File: /tmp/crontab.XXXXzBQgwS

*/5 * * * * ~/check_phpfpm.sh
*/5 * * * * ~/check_nginx.sh
*/5 * * * * ~/disk-clean.sh
*/5 * * * * ~/loadcheck.sh

By right my code should run every 5 minutes. but it doesn't run

[root@4D13 ~]# ls -l
total 756
-rw-------. 1 root root   1688 Dec 18 09:45 anaconda-ks.cfg
-rwxrwxrwx  1 root root    139 Dec 28 18:18 check_nginx.sh
-rwxrwxrwx  1 root root    140 Dec 28 18:19 check_phpfpm.sh
-rwxrwxrwx  1 root root    456 Dec 28 18:18 disk-clean.sh
-rw-r--r--. 1 root root  15469 Dec 18 09:45 install.log
-rw-r--r--. 1 root root   5267 Dec 18 09:44 install.log.syslog
-rwxrwxrwx  1 root root    503 Dec 19 19:26 loadcheck.sh
drwxr-xr-x  9 1001 1001   4096 Dec 18 11:08 nginx-1.3.2
-rw-r--r--  1 root root 722119 Jun 26  2012 nginx-1.3.2.tar.gz
[root@4D13 ~]#

It should run ~/check_phpfpm.sh as my code if i run manually it will work

[root@4D13 ~]#
[root@4D13 ~]# ~/check_phpfpm.sh
Stopping php-fpm:                                          [FAILED]
Starting php-fpm:                                          [  OK  ]

More about check_phpfpm, it is a script that check if the service php-fpm is running, if it not working ,it will execute and restart php-fpm, but the issue is if i run manually its work. but the crontab does not restart, the server php-fpm crashed and went to stop mode, but this script does not restart, my crontab should execute the script every 5 mins to check.

What is wrong with my crontab setup? Thanks for all help

user1916580
  • 23
  • 1
  • 1
  • 6
  • Cron will generally send you email about it's output. Can you check ur email using mail on your local system? – traditional Jan 01 '13 at 16:52
  • Why not just looking at the log file inside /var/log ? – benjarobin Jan 01 '13 at 16:53
  • Two common problems: not setting your environment (PATH, etc.) or not using the expected shell... the defaults to both are very minimal under cron. Running from command line but not under cron is a classic symptom of this. Quick test: */5 * * * * . ~/.profile && your_command – Gilbert Jan 01 '13 at 17:04
  • Don't assume anythig about current directory or PATH settings in cronjobs. Instead, set them explicitely. Also: I don't think that the tilde will be expanded, use an explicit path ( eg /home/root/myscript.sh ) – wildplasser Jan 01 '13 at 17:12
  • Who's crontab are those running as? I see the log files are owned by root, so in the crontab, what is `~`? – glenn jackman Jan 01 '13 at 20:51
  • You accepted Wololo's answer, but it's not clear how it solved your problem (the answer made several suggestions). Can you add a comment to the answer explaining what the actual solution was? This will make it more helpful to future readers. – Keith Thompson Jan 01 '13 at 21:30

2 Answers2

0

Are you sure the CRON service is firing? Maybe it is not even running.

Depending on your distro you can check that its running it not using something like...

# service crond status

If it is running, and your scripts are not firing then there is probably a permissions or location issue. Can you use ~ via CRON? Maybe try putting the absolute path to your scripts in such as /home/user/check_phpfpm.sh for example.

If your getting an error back from CRON, either check your CRON log, probably located at /var/log/cron or somewhere similar or have the CRON output emailed to you by adding the following on the first line of your CRONTAB...

MAILTO="you@whatever.com"
Happy
  • 806
  • 4
  • 7
0

First make sure your scripts are executable:

chmod u+x name_of_script

Now add it to crontab:

crontab -e

Also make sure you are writing the full path in the crontab e.g:

*/5 * * * * /home/user/loadcheck.sh
Hamed Al-Khabaz
  • 680
  • 4
  • 7
  • 2
    `crontab -e` (which edits your crontab) works, but personally I never use it. I keep my crontab file in a source control system and use `crontab filename` to install it. That way I avoid losing information, and it's easier to recover from mistakes. – Keith Thompson Jan 01 '13 at 21:32