cron job verification
Derek Martin
invalid at pizzashack.org
Wed Jan 12 00:16:01 EST 2005
On Tue, Jan 11, 2005 at 10:37:04AM -0500, Ed Lawson wrote:
> I have several cron jobs that I have written to sync various
> directories and to do backups. I did this via crontab -e as root.
> My question is how do I verify the operation of the these jobs. I
> thought there would be mail sent to root or its alias upon completion,
> but there is none.
Cron normally only produces e-mail if the script/command you ran had
output. The mail will go to the user as which the commands ran, in
this case root.
> What is the best way to receive verification or otherwise check on
> whether or not the job ran and if it ran to completion properly?
Well, rsync conveniently provides an exit status which indicates its
success or failure, which you can use to good effect. Wrap your cron
job in a shell script, which looks something like this:
#!/bin/sh
# NEVER start shell scripts as #!/bin/bash -- it can lead to strange
# and unintended results.
rsync <options>
if ! $? ; then
echo -e "\nrsync completed successfully!\n"
else
echo -e "\nrsync failed!\n!"
fi
# end of script
$? is always an integer which holds the exit status of the last
completed command (so there's never a need to put it in quotes, unless
you want to be sure the shell will treat it as a string). The if
statement basically says if the exit status is zero (success),
indicate success. Otherwise indicate failure. The ouput should be
mailed to root. There are a variety of ways to make your normal user
account get this mail, but the best is to simply alias root to your
normal account, as mentioned by someone else.
HTH!
--
Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address. Replying to it will result in
undeliverable mail. Sorry for the inconvenience. Thank the spammers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20050112/9a387f61/attachment.bin
More information about the gnhlug-discuss
mailing list