One of the features of your cPanel on your hosting account is the ability to create cron jobs. These are scripts that are scheduled to run at specified times and are set within your cPanel. There is an option on the setting screen that allows you to enter an email address so you are notified when a cron job finishes. There are times, however, when you may not get the email for some cron jobs but may for others. Below are the steps to take to ensure you always get an email after every cron.
How to be sure you get an email after every cron job
- First, log into your cPanel.
- Once you are in the main cpanel area, find the Advanced category. and click on the cron jobs icon.
- This leads you to the cron job setup screen. At the top you will see a Cron Email setting. This is where you will enter the email address to which you want to receive notice after every cron job. If you do not see an email address next to Current email:, you will need to enter one so you begin to receive emails.
- If you see an email address listed there and are still not receiving an email for one of more of your cron jobs, you need to ensure that those particular cron jobs are producing output. Any cron job that does not produce output will not send an email. To ensure some sort of output we need to edit the script itself. Look at the path of the cron job so you know where to edit the script. Write down the path if necessary so you do not forget.
- Once we know where the script is located, return to the main cPanel page. From here, open up the File Manager located in the Files category.
- Navigate to your script's location once inside the File Manager. Below, you will see our script, named mytestscript.php, is located in the public_html folder. Find your particular script file, highlight it, and then click on the Edit icon from the upper toolbar of the screen. You will be greeted with a popup. Click on the Edit button to open the editor.
- Inside the file, we want to add a single line to ensure there is some output. We will add a simple echo statement for our output.
echo "cron job completed";This output can be anything, a single word or sentence will do. Also, be sure you enter the line of code is before the php closing tag ?> of your script.
- Once entered, click on the Save Changes button at the top of the screen. You will now receive an email every time the cron job runs. Repeat the procedure for any other cron jobs that are not sending you an email.