I want my subject line to be "hostxx:yyDB refresh daily"
is there a way to do it
Thanks and Regards
Kaushal
03-24-2008, 08:14 AM
"Dirk Heinrichs"
crontab entry
Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
> MAILTO=systems@webaroo.com
> 0 18 * * * /home/kaushal/rsync_mysql.sh
>
> I want my subject line to be "hostxx:yyDB refresh daily"
>
> is there a way to do it
Don't rely on cron to send the mail, use mailx inside your script instead.
That means, inside the script, capture all output in a temp. file, then use
cat /tmp/file|mailx -s "my subject" systems@webaroo.com
HTH...
Dirk
03-24-2008, 08:32 AM
"Kaushal Shriyan"
crontab entry
On Mon, Mar 24, 2008 at 2:44 PM, Dirk Heinrichs <dirk.heinrichs@online.de> wrote:
Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
> MAILTO=systems@webaroo.com
> 0 18 * * * /home/kaushal/rsync_mysql.sh
>
> I want my subject line to be "hostxx:yyDB refresh daily"
>
> is there a way to do it
Don't rely on cron to send the mail, use mailx inside your script instead.
That means, inside the script, capture all output in a temp. file, then use
cat /tmp/file|mailx -s "my subject" systems@webaroo.com
HTH...
* * * *Dirk
Hi Dirk
Below is my script
################################################## ###########################
#!/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@host77:/var/lib/ >/tmp/rsync-${TIMESTAMP}.log 2>&1
then
******* echo "Success"
else
******* echo "Please check the file rsync-${TIMESTAMP}.log for errors."
fi
so according to your suggestion
where does this line fits "cat /tmp/file|mailx -s "my subject" systems@webaroo.com"
in my above bash script
Thanks and Regards
Kaushal
03-24-2008, 08:47 AM
"Dirk Heinrichs"
crontab entry
Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
> On Mon, Mar 24, 2008 at 2:44 PM, Dirk Heinrichs <dirk.heinrichs@online.de>
>
> wrote:
> > Am Montag, 24. März 2008 schrieb Kaushal Shriyan:
> > > MAILTO=systems@webaroo.com
> > > 0 18 * * * /home/kaushal/rsync_mysql.sh
> > >
> > > I want my subject line to be "hostxx:yyDB refresh daily"
> > >
> > > is there a way to do it
> >
> > Don't rely on cron to send the mail, use mailx inside your script
> > instead. That means, inside the script, capture all output in a temp.
> > file, then use
> >
> > cat /tmp/file|mailx -s "my subject" systems@webaroo.com
> >
> > HTH...
> >
> > Dirk
>
> Hi Dirk
>
> Below is my script
> ################################################## #########################
>##
>
> #!/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@host77:/var/lib/
>
> >/tmp/rsync-${TIMESTAMP}.log 2>&1
>
> then
> echo "Success"
> else
> echo "Please check the file rsync-${TIMESTAMP}.log for errors."
> fi
>
> ################################################## #########################
>##
>
> so according to your suggestion where does this line fits "cat
> /tmp/file|mailx -s "my subject" systems@webaroo.com" <systems@webaroo.com>
> in my above bash script
>
> Thanks and Regards
>
> Kaushal
Hmm, if the script is used from cron only, you could reduce it to the
following (note that when run from cron, you may need to use full paths to
your binaries, or set $PATH inside the script):
so according to your suggestion where does this line fits "cat
/tmp/file|mailx -s "my subject" systems@webaroo.com" <systems@webaroo.com>
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
> #!/bin/bash
> #rsync mysql database shell script
> #author kaushal
> #bash script file name rsync_mysql.sh
> #created on 24/03/2008
>
> TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S:%N`
>
> if /usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/ 2>&1 |
> /usr/bin/tee /tmp/rsync-${TIMESTAMP}.log | /usr/bin/mailx -s "host77 DB
> refresh daily" kaushal@example.com
>
> then
> echo "Success"
> else
> echo "Please check the file rsync-${TIMESTAMP}.log for errors."
> fi
>
> Please let me know if its correct
There's no need for the if-then-else part anymore. You get the whole output
mailed to the given address. However, if you follow Collins very good
proposal, you could do with:
if /usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/
> /tmp/rsync-${TIMESTAMP}.log 2>&1
then
subj_prefix="Success"
else
subj_prefix="Error"
fi
cat /tmp/rsync-${TIMESTAMP}.log| /usr/bin/mailx -s "${subj_prefix}: host77 DB
refresh daily" kaushal@example.com
So that you can tell from the subject wether the command was succesful or not.
Bye...
Dirk
03-24-2008, 10:06 AM
Peter Humphrey
crontab entry
On Monday 24 March 2008 10:19:25 Collin Starkweather wrote:
> ... you left a '>' out of your rsync call. It's fixed below.
His version is exactly the same as yours, apart from layout. I suggest that
the '>' at the beginning of a line has confused your mail reader.
--
Rgds
Peter
--
gentoo-user@lists.gentoo.org mailing list
03-24-2008, 11:25 AM
"Kaushal Shriyan"
crontab entry
On Mon, Mar 24, 2008 at 4:36 PM, Peter Humphrey <peter@humphrey.ukfsn.org> wrote:
On Monday 24 March 2008 10:19:25 Collin Starkweather wrote:
> ... you left a '>' out of your rsync call. It's fixed below.
His version is exactly the same as yours, apart from layout. I suggest that
the '>' at the beginning of a line has confused your mail reader.
--
Rgds
Peter
--
gentoo-user@lists.gentoo.org mailing list
Hi Collin
I have two scripts file
one is http://pastebin.com/m263e6f3c and http://pastebin.com/m175098db.
The requirement is run http://pastebin.com/m175098db script once the below line succeeds in the http://pastebin.com/m263e6f3c
if /usr/bin/rsync -av /var/lib/mysql host77:/var/lib/ > /tmp/rsync-${TIMESTAMP}.log 2>&1
then
* /usr/bin/mailx -s "Success: host77 DB refresh daily" kaushal@example.com < /tmp/rsync-${TIMESTAMP}.log
I am not able to proceed
Thanks and Regards
Kaushal
03-24-2008, 12:43 PM
Uwe Thiem
crontab entry
On Monday 24 March 2008, Kaushal Shriyan wrote:
> On Mon, Mar 24, 2008 at 4:36 PM, Peter Humphrey
> <peter@humphrey.ukfsn.org>
>
> wrote:
> > On Monday 24 March 2008 10:19:25 Collin Starkweather wrote:
> > > ... you left a '>' out of your rsync call. It's fixed below.
> >
> > His version is exactly the same as yours, apart from layout. I
> > suggest that
> > the '>' at the beginning of a line has confused your mail reader.
> >
> > --
> > Rgds
> > Peter
> > --
> > gentoo-user@lists.gentoo.org mailing list
>
> Hi Collin
>
> I have two scripts file
> one is http://pastebin.com/m263e6f3c and
> http://pastebin.com/m175098db.
>
> The requirement is run http://pastebin.com/m175098db script once
> the below line succeeds in the http://pastebin.com/m263e6f3c
>
> if /usr/bin/rsync -av /var/lib/mysql host77:/var/lib/ >
> /tmp/rsync-${TIMESTAMP}.log 2>&1
> then
> /usr/bin/mailx -s "Success: host77 DB refresh daily"
> kaushal@example.com < /tmp/rsync-${TIMESTAMP}.log
>
> I am not able to proceed
Make that last line:
cat /tmp/rsync-${TIMESTAMP}.log | mailx -s "blablabla"...
Uwe
--
Informal Linux Group Namibia:
http://www.linux.org.na/
SysEx (Pty) Ltd.:
http://www.SysEx.com.na/
--
gentoo-user@lists.gentoo.org mailing list