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
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
03-21-2008, 06:26 AM
Alan McKinnon
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
03-21-2008, 06:33 AM
"Kaushal Shriyan"
rsync script
On Fri, Mar 21, 2008 at 12:56 PM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> 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?
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
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
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
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".
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
03-21-2008, 12:23 PM
Albert Graham
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.
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
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