Operating System - HP-UX
1748227 Members
4123 Online
108759 Solutions
New Discussion юеВ

How to do Error Email if there is a Problem w/Script

 
SOLVED
Go to solution
Laurie A. Krumrey
Regular Advisor

How to do Error Email if there is a Problem w/Script

Hi Virtual Friends,

My scripted worked great with the remote copy
thank you for you help.

I have it setup in cron to run at 4am every
day. However I have two questions.

1. Will it just copy over files on the target
with existing names? I want it to over
write with the new source file, so hopefully
the answer is yes.

2. How do I add some error checking like
syserr to my script below, do I add the email
to my cron job???:

FILES="/db21/backup/*.gz /db22/backup/*.gz /db23/backup/*.gz "

Here's my script:
for FILE in ${FILES}
do
rcp -p ${FILE} naropa:${FILE}
remsh naropa chown syb115:syb115 $FILE
done

Here's my cron:
0 4 * * * /var/adm/backup 2> /dev/null


~
Happiness is a choice
4 REPLIES 4
Vincenzo Restuccia
Honored Contributor

Re: How to do Error Email if there is a Problem w/Script

0 4 * * * /var/adm/backup >ctrl.log 2>&1
add if>then>else in your script for ctrl.log and if you have errors sen email with mailx or sendmail.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to do Error Email if there is a Problem w/Script

Hi Laurie,

I happened to have a script that was extremely close so I added your emailing; it's commented out but remove the comments, set the proper addressee (ADDRESS). You will need to also set the variables GROUP and OWNER to change the ownerships of the remote files. The source and destination arrays will need to be set to your desired files. One improvement that I'll leave an an exercise for the reader is to determine the owner and group of the local file and use that data to set the values on the destination machine 'on the fly'. You may also need to add some PATH exports to run under cron.
Please see the attachment.

Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: How to do Error Email if there is a Problem w/Script

Oops, Laurie add an 'fi' after the echo | email statement.

Sorry, Clay
If it ain't broke, I can fix that.
Joseph C. Denman
Honored Contributor

Re: How to do Error Email if there is a Problem w/Script

You could also use || or &&

||(pipepipe) if first did not work do second
&& if first did work do second

example:

rcp -p ${FILE} naropa:${FILE} || echo "Files did not go" | mailx ............

or
rcp -p ${FILE} naropa:${FILE} && echo "Files did go" | mailx .........

Hope this helps...

...jcd...

If I had only read the instructions first??