Quoting Kaushal Shriyan <[EMAIL PROTECTED]>:

so according to your suggestion where does this line fits "cat
/tmp/file|mailx -s "my subject" [EMAIL PROTECTED]" <[EMAIL 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 [EMAIL PROTECTED]:/var/lib/ \
             > /tmp/rsync-${TIMESTAMP}.log 2>&1
  then
    cat /tmp/rsync-${TIMESTAMP}.log | \
      mailx -s "Success: hostxx:yyDB refresh daily" <[EMAIL PROTECTED]>
  else
    cat /tmp/rsync-${TIMESTAMP}.log | \
      mailx -s "Error: hostxx:yyDB refresh daily" <[EMAIL PROTECTED]>
  fi

Hope this helps,

Cheers,

-Collin

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

--
gentoo-user@lists.gentoo.org mailing list

Reply via email to