Link to home
Start Free TrialLog in
Avatar of simpsonjr
simpsonjr

asked on

Sendmail question.

Hello,

The old admin is getting email from completed cron jobs.  

1. where is this configured.
2. How could I update it to my email address.  

Here is the email that is coming in:


-----Original Message-----
From: WWW1 Super-User [mailto:root@****.****.com]
Sent: Monday, November 19, 2007 12:12 PM
To: root@***.***.com
Subject: Output from "cron" command

Your "cron" job on HOST
/usr/local/etc/rsync_web >/var/adm/rsync_web.log

produced the following output:

send_files failed to open downloads/fsp_acct.pdf: Permission denied
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Hi,

If the crontab job itself is not sending emails, then the default behavior of crontab is  to capture job output and mail it to the user running the job.

So, if root is the user that run the job, (s)he will continue to receive the emails. You may modify the jobs to send output to your email by piping the output to your mail command that send it to you.

e.g.

If your crontab job run something similar to

* * * * * /usr/bin/ls

then you may change it to

* * * * * /usr/bin/ls | /usr/bin/mail -s "ls output" youremailaddress

a more proper way is to redirect stdout & stderr to a file then mail the file

e.g.

* * * * * /path/to/myscript

where myscript has

/usr/bin/ls > /path/to/output.log 2>&1
/usr/bin/mail -s "ls output" youremailaddress < /path/to/output.log
Avatar of simpsonjr
simpsonjr

ASKER

omarfarid  

Here are the entries in the crontab. I think she is using the second approach, how do I check?

10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
2,7,12,17,22,27,32,37,42,47,52,57 * * * * /usr/local/etc/rsync_web >/var/adm/rsync_web.log
# Start Apache in case it stops
0,10,20,30,40,50 * * * * /usr/local/etc/start_apache.sh
# Switch over the Apache logs
0 0 1,8,15,22 * * /usr/local/etc/newapachelog

 

Hi,

if you want to list root crontab jobs:

As root run

crontab -l > mycrontab

you may edit (e.g. using vi) the file mycrontab to change the way crontab jobs are run

e.g. to change

* * * * * /usr/bin/ls

to

* * * * * /usr/bin/ls | /usr/bin/mail -s "ls output" youremailaddress

Then you may resubmit the crontab jobs

crontab mycrontab

ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I am root, can I just use crontab -e and modify the cronjob?

This admin is gone so, I want to have the root email changed to my email, how do I do that?  

Thanks  
Hi,

Although you can use the -e option to edit crontab jobs directly, but it is better to keep a copy of the current jobs schedules in a file and  edit the file then resubmit. Many administrators do mistakes while editing directly (and hence loose what what scheduled).

Now, coming to your question on how to send emails to you (not root).

There are many ways:

1- for each scheduled job just follow the example where you pipe output and errors to mail. I will take simple example and you can do similar

* * * * * /usr/bin/ls 2>&1 | mail -s "ls output" youremailaddress

2- Or you may edit each script scheduled and redirect output and error (of commands run in the script) to a file then email the file to your self. I will repeat the example here:

* * * * * /path/to/myscript

where myscript has

/usr/bin/ls > /path/to/output.log 2>&1
/usr/bin/mail -s "ls output" youremailaddress < /path/to/output.log

3- You may forward all emails coming to root to your self (All, which could be troublesome!) by creating /.forward file and add your email address to it. Please see

man forward

for more details
Thanks for all the help!!!!