FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 03-24-2008, 08:04 AM
"Kaushal Shriyan"
 
Default crontab entry

Hi I have the following entry in the crontab

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

Thanks and Regards

Kaushal
 
Old 03-24-2008, 08:14 AM
"Dirk Heinrichs"
 
Default 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
 
Old 03-24-2008, 08:32 AM
"Kaushal Shriyan"
 
Default 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
 
Old 03-24-2008, 08:47 AM
"Dirk Heinrichs"
 
Default 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):

/usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/
2>&1 |/usr/bin/tee /tmp/rsync-${TIMESTAMP}.log | /usr/bin/mailx -s "My
subject" systems@webaroo.com

This will mail the output and save it to a file at the same time.

HTH...

Dirk
 
Old 03-24-2008, 09:03 AM
"Kaushal Shriyan"
 
Default crontab entry

On Mon, Mar 24, 2008 at 3:17 PM, Dirk Heinrichs <dirk.heinrichs@online.de> wrote:

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):



/usr/bin/rsync -av /var/lib/mysql kaushal@host77:/var/lib/

2>&1 |/usr/bin/tee /tmp/rsync-${TIMESTAMP}.log | /usr/bin/mailx -s "My

subject" systems@webaroo.com



This will mail the output and save it to a file at the same time.



HTH...



* * * *Dirk


Hi Dirk,

Thanks Dirk

So the Final script looks like

################################################## ################################################## ##############


#!/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

################################################## ################################################## ##############


and the crontab entry would be

0 18 * * * /home/kaushal/rsync_mysql.sh


Please let me know if its correct

Thanks again

Thanks and Regards

Kaushal
 
Old 03-24-2008, 09:19 AM
Collin Starkweather
 
Default crontab entry

Quoting Kaushal Shriyan <kaushalshriyan@gmail.com>:


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

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
cat /tmp/rsync-${TIMESTAMP}.log |
mailx -s "Success: hostxx:yyDB refresh daily" <systems@webaroo.com>
else
cat /tmp/rsync-${TIMESTAMP}.log |
mailx -s "Error: hostxx:yyDB refresh daily" <systems@webaroo.com>
fi

Hope this helps,

Cheers,

-Collin

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

--
gentoo-user@lists.gentoo.org mailing list
 
Old 03-24-2008, 10:01 AM
"Dirk Heinrichs"
 
Default crontab entry

Am Montag, 24. März 2008 schrieb Kaushal Shriyan:

> So the Final script looks like

Is it the final script :-) ?

> #!/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
 
Old 03-24-2008, 10:06 AM
Peter Humphrey
 
Default 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
 
Old 03-24-2008, 11:25 AM
"Kaushal Shriyan"
 
Default 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
 
Old 03-24-2008, 12:43 PM
Uwe Thiem
 
Default 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
 

Thread Tools




All times are GMT. The time now is 01:08 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org