1835378 Members
2861 Online
110078 Solutions
New Discussion

mailx and cron

 
SOLVED
Go to solution
Dirk Kilian
Advisor

mailx and cron

I testet mailx as a cron job to send the status of our backup tasks:
omnistat -previous -last 1 | mailx -s "Omnistat last day"
-> this was working fine (I received the mail in my ofice)

Now I'm trying to put it in a shell script, that I can send the status in error situations only. The script is working fine (I receive a mail), when I start the script manually. But from cron it is not working. Here is the script:
#!/usr/bin/ksh
# **************************************
#
# Function: Check Omniback backup tasks and send a mail
# in case of errors
#
# Author: D.Kilian
#
# Date: 2002/07/08
#
# **************************************

mail_addr=dirk@nokia-ocd.com
temp_file=/tmp/omnistat.lst

export mail_addr
export temp_file

/opt/omni/bin/omnistat -previous -last 1 > ${temp_file}

if [ `cat ${temp_file} | grep -E 'Failed | Errors' | wc -l` -gt 0 ]
then
cat ${temp_file} | mailx -s "Backup Failure Omniback yesterday" ${mail_addr}
fi

rm ${temp_file}
*************************
So what's my mistake?

Dirk
4 REPLIES 4
Christopher McCray_1
Honored Contributor

Re: mailx and cron

Hello,

You need to use the full path to your commands (cat, mailx, etc), or define your path:

PATH=/usr/bin:/sbin:/usr/sbin
export PATH

Hope this helps

Chris
It wasn't me!!!!
Leif Halvarsson_2
Honored Contributor
Solution

Re: mailx and cron

Hi
Do you know if the job is started at all ?
If it is started, do you get any errors ? I am not quite sure how cronjob errors are handled but it is always possible to redirect stdout and stderr of your script to a temporary file.

Which version of OmniBack do you use, there are perhaps easier ways to mail session status.

Dirk Kilian
Advisor

Re: mailx and cron

Hi,

thank you for your answers. Both were helpful. But the best was the hint to redirect the output of stderr to a temp file. There I saw my mistake. I gave cron a wrong location of my script. Now it is working.

Dirk
MANOJ SRIVASTAVA
Honored Contributor

Re: mailx and cron

Hi Dirk


Also in case you have croned the job any failures or the o/p message get mailed to root by default so you can also check the mail for the root bi eithe mail or vi /var/mail/root and check for the messges for that time in that file .


Manoj Srivastava