Send cronjob output to multiple email addresses.

By default, cronjob will send the output of the command to the owner’s system mail box. In Linux, you can route the mail using

MAILTO=user@server.com
* * * * * /some/command.sh

in the crontab.

Some how, if I did that in Solaris, I got the following error:

MAILTO=user@server.com
crontab: error on previous line; unexpected character found in line.
crontab: errors detected in input, no crontab file generated.

So, I have to use mail aliases. First, I’ll have to edit the file

vi /etc/mail/aliases

Assume the cronjob owner is called user1 and I need to leave the cronjob result in the owner’s inbox, forward a copy to user2 and another copy to an external email address user@server.com, I’ll add the following lines to the end of the file.

user1:user1,user2,user@server.com

Then, I’ll refresh the mail system’s alias database with the following command:

newaliases

That’s all.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: