Java Mailing List Archive

http://www.redhatconfig.com/

Home » Gentoo Linux »

Re: [gentoo-user] crontab entry

Collin Starkweather

2008-03-24

Replies: Find Java Web Hosting

Author LoginPost Reply
Quoting Kaushal Shriyan <kaushalshriyan@(protected)>:

> so according to your suggestion where does this line fits "cat
> /tmp/file|mailx -s "my subject" systems@(protected)>
> in my above bash script

Dirk gave a lovely one-liner, but my guess is you'll get sick of
having to actually check the body of the e-mail to know whether there
is a problem, so you could also put the system call to mailx in the
if-then-else-fi and indicate in the subject line whether it is a
success or failure.

Also, you want to cut out the echo or else cron will send an e-mail
(remember cron sends an e-mail if there's any output from the
command), which is redundant now that you're calling mailx.

Finally, note that you left a '>' out of your rsync call. It's fixed below.

 #!/bin/bash
 #rsync mysql database shell script
 #author kaushal
 #created on 21/03/2008

 TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S:%N`

 if rsync -av /var/lib/mysql kaushal@(protected)/ \
        > /tmp/rsync-${TIMESTAMP}.log 2>&1
 then
  cat /tmp/rsync-${TIMESTAMP}.log | \
    mailx -s "Success: hostxx:yyDB refresh daily" <systems@(protected)>
 else
  cat /tmp/rsync-${TIMESTAMP}.log | \
    mailx -s "Error: hostxx:yyDB refresh daily" <systems@(protected)>
 fi

Hope this helps,

Cheers,

-Collin

--
Collin Starkweather, Ph.D.
http://www.linkedin.com/in/collinstarkweather

--
gentoo-user@(protected)

©2008 redhatconfig.com - Jax Systems, LLC, U.S.A.