Add more email id in cron mail

By default, the cron daemon in Linux sends emails to the user's email address specified in the /etc/passwd file. However, you can modify the cron configuration to send emails to multiple recipients.

Here are a few ways to add more email IDs to the cron mail:

Method 1: Using the MAILTO variable

You can set the MAILTO variable in the /etc/crontab file to specify multiple email addresses. For example:

MAILTO="[email protected],[email protected],[email protected]"

This will send emails to all three email addresses.

Method 2: Using the cron command-line option

You can use the -m option with the cron command to specify multiple email addresses. For example:

crontab -e -m "[email protected],[email protected],[email protected]"

This will edit the cron table and add the specified email addresses.

Method 3: Using a separate email configuration file

You can create a separate configuration file, e.g., /etc/cron/email.conf, and specify the email addresses in that file. Then, update the cron configuration to use that file.

For example, create a file /etc/cron/email.conf with the following content:

MAILTO="[email protected],[email protected],[email protected]"

Then, update the /etc/crontab file to include the email configuration file:

@reboot /usr/sbin/cron -f /etc/cron/email.conf

Restart the cron service to apply the changes.

Method 4: Using a script

You can create a script that sends emails to multiple recipients using a tool like mail or sendmail. Then, schedule the script to run using cron.

For example, create a script /usr/local/bin/send_email.sh with the following content:

#!/bin/bash

# List of email addresses
EMAIL_ADDRESSES="[email protected],[email protected],[email protected]"

# Send email to each address
for email in $EMAIL_ADDRESSES; do
  echo "Hello from cron!" | mail -s "Cron Job" $email
done

Make the script executable and add it to the cron table:

crontab -e

Add the following line to the cron table:

@reboot /usr/local/bin/send_email.sh

Restart the cron service to apply the changes.

Remember to replace the email addresses with the actual addresses you want to send emails to.