Introduction
You may use the following procedure to enable cron notifications via the command line.
Procedure
1. Login to SSH or Terminal
2. First list the existing crontab. If you are the root user, you can view any other user's crontab with the -u flag. If you are a regular user, you would omit the -u flag because you cannot access other user's crontabs.
Here are some example commands as the root user:
crontab -l -u exampleusername # Displays the crontab of the exampleusername cPanel user
crontab -l -u root # Displays the crontab of the root user
You would use the following command as a regular user to display your own crontab:
crontab -l
3. Now that you know what is already in the crontab, you can edit it with the following commands.
As the root user:
crontab -e -u exampleusername # Edits the crontab of the exampleusername cPanel user
crontab -e -u root # Edits the crontab of the root user
As a regular cPanel user, you can only edit your own crontab:
crontab -e
4. Once you execute the command to edit the crontab you will need to add your desired destination IP address for cron emails in the following format.:
MAILTO="emailaccount@example.tld"
The crontab is read from top to bottom. That means that if you put this configuration before all of your cron commands, all of the cron commands will send their messages to that email address.
If you place this configuration after the first cron command, but before the rest, it will only apply to the commands below it. There are other variations that you can research if you need further flexibility. You'd need to consult with a systems administrator if you need assistance with this.
5. Save your edits, and now the next time a cron is run that generates a notification, it will send to your desired email address.
Other Potential Locations For the MAILITO environment variable
There are other potential locations where you may set, or you may find that someone else has set the MAILTO environment variable. If you'd like to learn about this in more depth, please read the cron man pages in full with the following commands:
man cron
man crond
man crontab
man 5 crontab
When reviewing the documentation, it is important to remember that the MAILTO configuration is a standard environment variable, so it can be configured anywhere that you would configure other environment variables, and it will be subject to the same inheritance and overrides as other environment variables.
One easy way to quickly check for a configuration that was set up by someone else is use grep to search the server's configuration files for the environment variable:
grep -R MAILTO /etc/
Comments
0 comments
Article is closed for comments.