A cron job is a time-based task that is set to run at certain intervals from within your cPanel. It sets a particular script to run at a specific time or times on autopilot. There are different types of cron jobs. Some produce output and others do not. It is easier to determine if the cron ran for those that produce output (a file, email, or webpage output). However, for those that simply perform tasks behind the scene, you will need to tap into the server logs to determine if they have run. Below is a quick tutorial on checking your cron logs to determine if a job has run as it was scheduled.
(For developers or sysadmins experienced with the command line, get High Availability and Root Access for your application, service, and websites with Cloud VPS Hosting).
Checking your Cron job via server logs
- Open your preferred your SSH client. If you need an SSH client, we recommend PuTTY. You can download PuTTY here.
- Login to your server via your SSH client.
- Once logged in as the root user, use the following command to check the log for the cron script. The command will use the following format: grep “script.php” /path/file.ext. For instance, the code below is looking for the script cronscript.php in the cron.log file, which is in the /var/log folder.
grep “cronscript.php” /var/log/cron
- Hit Enter after that and the results, if any, will display like below:
Feb 24 02:33:02 ecbiz108 crond: (userna5) CMD (php -q /home/userna5/public_html/cronscript.php)
Feb 25 02:33:01 ecbiz108 crond: (userna5) CMD (php -q /home/userna5/public_html/cronscript.php)
Feb 25 11:45:01 ecbiz108 crond: (userna5) CMD (php -q /home/userna5/public_html/cronscript.php)
- Looking at the output, you will see the date and time the cron job has run. This is followed by the server name, cron ID, the cPanel username, and the command that ran. At the end of the command, you will see the name of the script.