Operating System - HP-UX
1833964 Members
2074 Online
110063 Solutions
New Discussion

Re: cron keeps sending mail to root

 
SOLVED
Go to solution
tom quach_1
Super Advisor

cron keeps sending mail to root

Hello,
i have 2 questions Please help!

the script below run every minute to check for a deamon.
every time it run, it send mail to root.
How can i stop it from sending mail to root just for this job. because i have many jobs running and need cron report.

2-someone please let me know how to append to a file whenever the argument #2 is true.

Regards,
Tom


#!/usr/bin/sh
# This script will check for Cognos every 30 seconds
# and if Cognos daemon is not available. It will restart


NAME=`ps -ef |grep [l]icense1 | awk '{print $8}'`

if [ "cognos1d" = "$NAME" ]
then
echo "License Manager is already running \n"
# mailx -r root@sunuxdev -s "Checking Cognos license manager `uname -n` `date`"
tquach@sunrider.com < /util/run/cognosr
exit 0
else
/opt/cognos/license1/lmgrd

mailx -r root@sunuxdev -s "Checking Cognos license manager`uname -n` `date`" tqu
ach@sunrider.com < /util/run/cognoss

fi
~
~
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: cron keeps sending mail to root

crontab -l

You will see a | mailx -s with an email address.

You need to take that part of the cron command line out and root will stop getting the mail.

Or

Looking at your code comment out hte line htat says mailx -r

mailx is the program being used to send the mail.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
D Block 2
Respected Contributor

Re: cron keeps sending mail to root

Tom,

I agree, comment out this line:

mailx -r root@sunuxdev -s "Checking Cognos license manager`uname -n` `date`" tqu

with a hash, we call it, "#" or

#mailx -r root@sunuxdev -s "Checking Cognos license manager`uname -n` `date`" tqu
Golf is a Good Walk Spoiled, Mark Twain.
Devesh Pant_1
Esteemed Contributor
Solution

Re: cron keeps sending mail to root

Hi Tom,
the output from cron gets mailed to the owner of the process, or the person specified in the MAILTO variable, but what if you don't want that? If you want to mail the output to someone else, you can
just pipe the output to the command mail.
e.g.

* 12 10,12,14,16 * * root backup.sh | mail -s "Subject of mail" user

If you wish to mail the output to someone not located on the machine, in the
above example, substitute user for the email address of the person who
wishes to receive the output.

If you have a command that is run often, and you don't want to be emailed
the output every time, you can redirect the output to a log file (or /dev/null, if you really don't want the output).
e,g

* 12 10,12,14,16 * * root backup.sh >> log.file

Notice we're using two > signs so that the output appends the log file and
doesn't clobber previous output.
The above example only redirects the standard output, not the standard error,
if you want all output stored in the log file, this should do the trick:

* 12 10,12,14,16 * * root backup.sh >> logfile 2>&1

You can then set up a cron job that mails you the contents of the file at
specified time intervals, using the cmd:

mail -s "logfile for cmd"
thanks
Devesh
john korterman
Honored Contributor

Re: cron keeps sending mail to root

Hi,
your script mails to root because it is run from root's crontab and produces some kind of output to std. out/std. error, which it cannot write elsewhere, e.g. "echo Licence Manager..".
Apart from the above mentioned possibilities you can change and test your script on the command line until it produces no output, or take care in the crontab that std. err and std. out are redirected, e.g. like this:

* * * * * /usr/local/bin/check_cognos.sh >/tmp/check_cognos.out 2>&1

The above should be on a single line and will prevent mailing to root.

regards,
John K.
it would be nice if you always got a second chance
Alain Tesserot
Frequent Advisor

Re: cron keeps sending mail to root

Do this and you will only get email if there is a problem. Standard output will be sent to /dev/null

* * * * * /path_to_script/your_script 1>/dev/null
tom quach_1
Super Advisor

Re: cron keeps sending mail to root

Thank you all for your help.

0-59 * * * * /util/run/startcognos.sh > /dev/null 2>&1
this one works fine, but it will send all output to null

what if i just want this condition to send out mail to me only. is it possible?

else
/opt/cognos/license1/lmgrd

mailx -r root@sunuxdev -s "Checking Cognos license manager`uname -n` `date`" tqu
ach@sunrider.com < /util/run/cognoss

Thanks,
Tom
D Block 2
Respected Contributor

Re: cron keeps sending mail to root

Tom,

keep the "/dev/null if you like, but redirect the output to a temp-file, then you can do an email.. to you using the
temp-file as email to you.

ex.

# reset temp file to zero bytes

> /tmp/tom.tempfile

if [ "cognos1d" = "$NAME" ]
then

# append to the temp file by >>
echo " `date` " >> /tmp/tom.tempfile
echo "Lic Mgr.." >> /tmp/tom.tempfile

else
# start the lic mgr up

/opt/cognos/license1/lmgrd
RET=$?
echo "lmgrd ret=$RET" >> /tmp/tom.tempfile
fi

# now send the mail to myself
# only send the tom.tempfile

mailx -s "Checking Cognos license manager`uname -n` `date`" tach@sunrider.com < /tmp/tom.tempfile

# you can add more echo to the temp.file
# thought the return code $RET is important
# so tract this to the temp-file.








Golf is a Good Walk Spoiled, Mark Twain.