Solved

Sendmail question.

Posted on 2007-11-19
7
300 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:simpsonjr
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20314046
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
0
 

Author Comment

by:simpsonjr
ID: 20314119
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

 

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20314127
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

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 40

Accepted Solution

by:
omarfarid earned 250 total points
ID: 20314195
Hi,

The initial posting you made seams to be coming from

2,7,12,17,22,27,32,37,42,47,52,57 * * * * /usr/local/etc/rsync_web >/var/adm/rsync_web.log

As you can see, the rsync_web sends output to /var/adm/rsync_web.log , but the sdterr (standard error) is not redirected and hence errors (as I think is the case) are captured and emailed to root.

Now, you can change the line to

2,7,12,17,22,27,32,37,42,47,52,57 * * * * /usr/local/etc/rsync_web >/var/adm/rsync_web.log 2>&1

This will send errors as well to the log file, which you can check from time to time. If you do not want errors to go to the same file, then change to something like

2,7,12,17,22,27,32,37,42,47,52,57 * * * * /usr/local/etc/rsync_web >/var/adm/rsync_web.log 2> /var/adm/rsync_web_errors.log

do not foreget to resubmit your crontab jobs as described earlier
0
 

Author Comment

by:simpsonjr
ID: 20314211
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  
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20314366
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
0
 

Author Comment

by:simpsonjr
ID: 20314467
Thanks for all the help!!!!

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outlook 2013 and Gmail via IMAP all messed up - lost cause?! 8 74
hosting email transfer 3 45
Install MySQL 5.6 and PHP on Centos Linux 6 122
SPF record issue 6 37
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question