1821246 Members
2904 Online
109632 Solutions
New Discussion юеВ

Cron email destination

 
SOLVED
Go to solution
Randy Hagedorn
Regular Advisor

Cron email destination

We have cron set up using the default of sending its output to e-mail. This requires the root user to be the only person that can view or delete these emails. I would like to allow other users to view or delete these as a daily maintenance activity, but do not want to allow them to login as root, due to security reasons.

Is there a way to do this?

Thanks
10 REPLIES 10
someone_4
Honored Contributor

Re: Cron email destination

what about changing the permission on the email file ? what about a permission of 777
This will allow everyone to read write and execute.
chmod 777 file name

Richard
A. Clay Stephenson
Acclaimed Contributor

Re: Cron email destination

The most straightforward way would be to have your cron script itself mail all output to the various users. On easy method would be to redirect all stdout and stderr within the cron script to a temp file and as the last operation of the cron job mail a copy of this file to the users in question and then delete the temp file.

Clay
If it ain't broke, I can fix that.
someone_4
Honored Contributor

Re: Cron email destination

Hey Mr A.
would this work using a .forward file?

Richard
James R. Ferguson
Acclaimed Contributor

Re: Cron email destination

Hi:

You can create a ".forward" file under the root user (where your processes run) and forward the resulting email to the control of another user who could then read and/or delete the mail.

Simply create a .forward file with the user's name in it and put it in the home directory ("/" for root, usually). It need only be readable by its owner.

...JRF...
someone_4
Honored Contributor

Re: Cron email destination

But with the .forward set up.
Everyone would have to edit or delete their own file.But they will have all the same info.


Richard
Fred Martin_1
Valued Contributor

Re: Cron email destination

If you don't mind these people reading -all- of root's mail, you could have a cron script fire off daily that would append /var/mail/root to /var/mail/user.

Other than that I would do what someone already mentioned - have the job send the mail to appropriate parties in the first place.

By the way, since people come and go, I rarely hard-code usernames into scripts for email. Instead hard-code an alias and put the users in your aliases file.

For example, in /etc/mail/aliases:
backupadm: user1,user2

Then your scripts would send mail to backupadm.

Fred
fmartin@applicatorssales.com
Thierry Poels_1
Honored Contributor

Re: Cron email destination

Hi,

how about having more cron-users? Only possible if root-privileges are not required though.

BTW I fully agree with Steve Martin: avoid having email-addresses scattered around your system: use aliases! People don't only come and go, sometimes email addresses have to be changed due to company policy, reorganization, take-over, ... . Bonus points here ;)

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Thierry Poels_1
Honored Contributor

Re: Cron email destination

sjips, little lapsus :(
Please read Fred Martin instead of "Steve" Martin
mea culpa
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Sanjay_6
Honored Contributor
Solution

Re: Cron email destination

Hi,

You can try this one too. Let the cron job create a temporary say "temp_file" file and update it for all the std output messages by using the redirector >>. Then at the end of the script u can use the mail option to mail it to as many user you want. Use this at the end of the script being run as cron job

mailx -s Subject mail-address < temp_file

this way you won't redirect all the mails addressed to root to the specified user. If you crate a .forward file in the root home directory you end up forwarding all root mails to the user(s) specified in the .forward file. To forward the cronjob output to multiple users you can repete the mailx line with another mai_address.


Randy Hagedorn
Regular Advisor

Re: Cron email destination

I would like to thank all those that replied to my query with E-mail. My limited knowledge about the capabilities of cron and mail has been greatly increased with all of the remarks. The forums are a tremendous supply of help.

Thanks again, Dewy