On 30/08/2006, at 11:17 AM, Kevin Fitzgerald wrote:

Pretty easy one I imagine. I am doing an rsync between 2 servers and would like to get the results emailed to me once the script completes. I tried adding > mailx -s "subject" [EMAIL PROTECTED] to the end of my script but I
got errors.

So what do I do?

Box is Fedora Core 4
Sendmail service is running

Here's the way I normally handle this sort of thing:

Create script that you will call from cron with the following script variables:

[EMAIL PROTECTED]
MAILSUB="Results from myscript"
RESULT=/tmp/myscript.out

Then set the umask for the script so the temp file is secure before you write to it, and create the temp file:

umask 077
rm -rf $RESULT >/dev/null 2>&1
touch $RESULT

You should check the result of the "rm" and possible the "touch" to make sure nothing bad happend.

Then simply run your rsync, output the results to $RESULT and send the mail:

rysnc [with all the opts] > $RESULT
mail -s "$RESULT" $MAILTO < $RESULT

Voila! You probably want to tidy up the temp file when you're done too, but I'll leave that as an exercise for you. If you need more than one person to receive the results, I usually create an alias in sendmail (/etc/aliases) with the necessary recipients then set the $MAILTO to match the alias.

Cheers,

James


--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to