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 > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 03-21-2008, 05:52 AM
"Kaushal Shriyan"
 
Default rsync script

Hi

MAILTO=kaushal@example.com
0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/

If i put this two lines in crontab it will run correctly,My requirement was to create a script, this script should indicate success or failures and the reason for failure


Any ideas

Thanks and Regards

Kaushal
 
Old 03-21-2008, 05:54 AM
"Kaushal Shriyan"
 
Default rsync script

Hi

MAILTO=kaushal@example.com
0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/

If
i put this two lines in crontab it will run correctly,My requirement
was to create a script, this script should indicate success or failures
and the reason for failure


Any ideas

Thanks and Regards

Kaushal
--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 03-21-2008, 06:26 AM
Alan McKinnon
 
Default rsync script

On Friday 21 March 2008, Kaushal Shriyan wrote:
> Hi
>
> MAILTO=kaushal@example.com
> 0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/
>
> If i put this two lines in crontab it will run correctly,My
> requirement was to create a script, this script should indicate
> success or failures and the reason for failure

crontab will only send a mail is there is anyput to stdout. What output
do you get if you run the rsync manually?

Do you have any packages installed that can actually send the mail?



--
Alan McKinnon
alan dot mckinnon at gmail dot com

--
gentoo-user@lists.gentoo.org mailing list
 
Old 03-21-2008, 06:33 AM
"Kaushal Shriyan"
 
Default rsync script

On Fri, Mar 21, 2008 at 12:56 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:

On Friday 21 March 2008, Kaushal Shriyan wrote:

> Hi

>

> MAILTO=kaushal@example.com

> 0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/

>

> If i put this two lines in crontab it will run correctly,My

> requirement was to create a script, this script should indicate

> success or failures and the reason for failure



crontab will only send a mail is there is anyput to stdout. What output

do you get if you run the rsync manually?


Hi Alan


When i run the rysnc command by hand, it runs successfully without any issues. I can see it on stdout saying building list files........ and then the rsync process
*


Do you have any packages installed that can actually send the mail?


*I did not understand this question

Thanks and Regards

Kaushal








--

Alan McKinnon

alan dot mckinnon at gmail dot com



--

gentoo-user@lists.gentoo.org mailing list
 
Old 03-21-2008, 07:33 AM
Collin Starkweather
 
Default rsync script

Quoting Kaushal Shriyan <kaushalshriyan@gmail.com>:


On Fri, Mar 21, 2008 at 12:56 PM, Alan McKinnon <alan.mckinnon@gmail.com>
wrote:


On Friday 21 March 2008, Kaushal Shriyan wrote:
> Hi
>
> MAILTO=kaushal@example.com
> 0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/


Run rsync through a script that tests the exit value, then prints an
error message if the exit value is not equal to 0 and nothing
otherwise. Run the script from cron and it will send you an e-mail if
there is a problem.


In bash, $? is the exit value of the last command. This is a bit
verbose, but you could put the following in rsync-host77.sh:


#!/bin/bash
TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S:%N`
rsync -av /bogus foo@bar:/bogus/ &>rsync-${TIMESTAMP}.log
EXITVALUE=$?
if [[ "${EXITVALUE}" -ne "0" ]]
then
echo "Error: rsync exited with status ${EXITVALUE}"
echo " "
echo "Please check the file rsync-${TIMESTAMP}.log for errors."
fi

To find exit values and their corresponding meanings, search for "EXIT
VALUES" in


http://www.linuxmanpages.com/man1/rsync.1.php

Hope this helps,

-Collin

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

--
gentoo-user@lists.gentoo.org mailing list
 
Old 03-21-2008, 07:59 AM
"Kaushal Shriyan"
 
Default rsync script

On Fri, Mar 21, 2008 at 2:03 PM, Collin Starkweather <gentoo@collinstarkweather.com> wrote:

Quoting Kaushal Shriyan <kaushalshriyan@gmail.com>:



> On Fri, Mar 21, 2008 at 12:56 PM, Alan McKinnon <alan.mckinnon@gmail.com>

> wrote:

>

>> On Friday 21 March 2008, Kaushal Shriyan wrote:

>> > Hi

>> >

>> > MAILTO=kaushal@example.com

>> > 0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/



Run rsync through a script that tests the exit value, then prints an

error message if the exit value is not equal to 0 and nothing

otherwise. *Run the script from cron and it will send you an e-mail if

there is a problem.



In bash, $? is the exit value of the last command. *This is a bit

verbose, but you could put the following in rsync-host77.sh:



* #!/bin/bash

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

* rsync -av /bogus foo@bar:/bogus/ &>rsync-${TIMESTAMP}.log

* EXITVALUE=$?

* if [[ "${EXITVALUE}" -ne "0" ]]

* then

* * * * echo "Error: *rsync exited with status ${EXITVALUE}"

* * * * echo " "

* * * * echo "Please check the file rsync-${TIMESTAMP}.log for errors."

* fi



To find exit values and their corresponding meanings, search for "EXIT

VALUES" in



* http://www.linuxmanpages.com/man1/rsync.1.php



Hope this helps,



-Collin



--

Collin Starkweather, Ph.D.

http://www.linkedin.com/in/collinstarkweather



--

gentoo-user@lists.gentoo.org mailing list




Hi Collin

Thanks Collin

Correct me if i am wrong please. I want to understand your script

step 1 : put the above code in text file and name it as rsync-host77.sh in the folder /home/kaushal in the machine where rsync command will execute


step 2 :*

cd /home/kaushal
$crontab -e
*
0 18 * * * rsync -host77.sh

If i want to run the rsync script at 6 pm everyday* ********

Also where will the "rsync-${TIMESTAMP}.log" file will be located, I believe it will be in /home/kaushal folder. Lets say if i have to put "rsync-${TIMESTAMP}.log" in /tmp folder


then the above rsync line would look like

rsync -av /bogus foo@bar:/bogus/ &>/tmp/rsync-${TIMESTAMP}.log

is that correct what i understand from your email

Thanks a Lot again

Thanks and Regards


Kaushal
 
Old 03-21-2008, 08:38 AM
Collin Starkweather
 
Default rsync script

Quoting Kaushal Shriyan <kaushalshriyan@gmail.com>:


Correct me if i am wrong please. I want to understand your script

step 1 : put the above code in text file and name it as rsync-host77.sh in
the folder /home/kaushal in the machine where rsync command will execute

step 2 :

cd /home/kaushal
$crontab -e

0 18 * * * rsync -host77.sh

If i want to run the rsync script at 6 pm everyday

Also where will the "rsync-${TIMESTAMP}.log" file will be located, I believe
it will be in /home/kaushal folder. Lets say if i have to put
"rsync-${TIMESTAMP}.log" in /tmp folder

then the above rsync line would look like

rsync -av /bogus foo@bar:/bogus/ &>/tmp/rsync-${TIMESTAMP}.log

is that correct what i understand from your email


You are correct, sir! You must also, of course, be sure to chmod u+x
rsync-host77.sh.


Note that if you want an e-mail on either success or failure (your
original post seemed to indicate this might be the case) bash
understands "if-then-else-fi".


Cheers,

-Collin

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

--
gentoo-user@lists.gentoo.org mailing list
 
Old 03-21-2008, 11:22 AM
Alan McKinnon
 
Default rsync script

On Friday 21 March 2008, Kaushal Shriyan wrote:
> On Fri, Mar 21, 2008 at 12:56 PM, Alan McKinnon
> <alan.mckinnon@gmail.com>
>
> wrote:
> > On Friday 21 March 2008, Kaushal Shriyan wrote:
> > > Hi
> > >
> > > MAILTO=kaushal@example.com
> > > 0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/
> > >
> > > If i put this two lines in crontab it will run correctly,My
> > > requirement was to create a script, this script should indicate
> > > success or failures and the reason for failure
> >
> > crontab will only send a mail is there is anyput to stdout. What
> > output do you get if you run the rsync manually?
>
> Hi Alan
>
> When i run the rysnc command by hand, it runs successfully without
> any issues. I can see it on stdout saying building list files........
> and then the rsync process

Most likely cause is that he shell that crontab runs in is NOT the same
shell as your user account and does not have the same PATH.

Solution: never rely on PATH in a crontab, supply the full PATH
yourself. Try calling rsync as /usr/bin/rsync as see if that fixes it

> > Do you have any packages installed that can actually send the mail?
>
> I did not understand this question

crontab does not do SMTP, it does not know how to send mail. You need a
mailer to be installed - like sendmail or mail


--
Alan McKinnon
alan dot mckinnon at gmail dot com

--
gentoo-user@lists.gentoo.org mailing list
 
Old 03-21-2008, 12:23 PM
Albert Graham
 
Default rsync script

One suggestion:

Wrap the rsync command and error checking in another script that you
call from cron, the new script checks for errors, if none, output
nothing, else output the error message, that way you only get the mail
if there was an error.


Albert.

Kaushal Shriyan wrote:

Hi

MAILTO=kaushal@example.com <mailto:kaushal@example.com>
0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/

If i put this two lines in crontab it will run correctly,My
requirement was to create a script, this script should indicate
success or failures and the reason for failure


Any ideas

Thanks and Regards

Kaushal


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 03-21-2008, 04:11 PM
Les Mikesell
 
Default rsync script

Kaushal Shriyan wrote:

Hi

MAILTO=kaushal@example.com
0 18 * * * rsync -av /var/lib/mysql kaushal@host77:/var/lib/

If i put this two lines in crontab it will run correctly,My requirement was
to create a script, this script should indicate success or failures and the
reason for failure



Rsync should already be telling you that in the email that cron sends
but you probably aren't bothering to read it because the -v option makes
it too verbose. If you you can't get rsync to say exactly what you want
with some variation (or omission) of the -v and -q options you could
replace the success output with an invocation like:
0 18 * * * rsync -a /var/lib/mysql kaushal@host77:/var/lib/ >dev/null &&
echo Rsync succeeded


Cron only sends mail if the command generates anything on stdout or
stderr. The >dev/null will discard normal output but keep any error
messages from rsync (which would go to stderr instead of stdout). If
the run succeds with no error, the command to the right of the && will
run so you still get an email.


Somehow the way you stated the 'requirement' for a script makes this
sound like a homework assignment from someone who expects it to look
like cobol, though...


--
Les Mikesell
lesmikesell@gmail.com



--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 09:56 PM.

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