How to test cron in Centos

User login

Here you can find some simple tests that would confirm the smooth functionality of your crontab.

Test if cron is running

Type the following command:

ps ax | grep cron 

Make sure that cron shows up. Expected output should be something like

[konordo@konordoserv]# ps ax | grep cron
1185 pts/1    S+     0:00 grep cron
1771 ?        Ss     0:00 crond

Test if cron is working

Add the following entry to your crontab. To do so, enter the command

crontab -e

And then add:

* * * * * /bin/echo "foobar" >> /your-path/your-file-name.txt 

After a minute, a file should be created under the specified path, holding the "foobar" content. If you can see the file, congrats, cron is working fine.

Test if your command is working

Add the following to your crontab:

* * * * * /bin/foobar > /your-path/your-file-name.txt 2>&1

and check for errors in look for errors in your-file-name.txt

Test for cron errors - the cron log

You can always check the cron log for errors. The usual location for that would be:

/var/log/cron

or

/var/log/messages

/var/log/cron.log or /var/log/messages for errors

Tags: 
Server configuration, CentOS