Crontab command – working status, log, cron job

Spread the love

When setup crontab on the server, it’s hard to check whether it’s working properly or not.

There’s command to check the status and log.

To check cron status and see the latest cronjob:

/etc/init.d/cron status

To start running:

service cron start

To stop running:

service cron stop

To restart running:

service cron restart

Cronjob example:

Running php script every minute:

* * * * * /usr/bin/php -e /websites/example.php > /dev/null 2>&1

/dev/null  this line is added for no log

If you want to see running log:

* * * * * /usr/bin/php -e /websites/example.php > /home/user/cron.log 2>&1

/dev/null  this line is added for saving to log file

Running php script every 2 minutes, which will run 30 times per hour:

*/2 * * * * /usr/bin/php -e /websites/example.php > /dev/null 2>&1

Running php script every 10 minutes, which will run 6 times per hour:

*/10 * * * * /usr/bin/php -e /websites/example.php > /dev/null 2>&1

Running php script designated minutes, this will running every 1,11,21,31,41,51 minutes:

1,11,21,31,41,51 * * * * /usr/bin/php -e /websites/example.php > /dev/null 2>&1

Running php script once a day, this will running at 1:00am every day:

0 1 * * * /usr/bin/php -e /websites/example.php > /dev/null 2>&1

Let’s keep the time well.

Facebook Comments

Published by

Titus Choi

I love technology. Working for information technology. Interested in AVR technology. Playing with RC stuff.