Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have just create a mysqldump script which i am using for dumping my data base and get confirmation by email.
script working fine when i missed my destination it shows the error in mail otherwise its shows success mail. but when i stop the mysqld service and run the script again i got success!! email which should be error email becoz mysqldump is not working.
Here is my script
############## get a list of all the databases ###########
for db in $(mysql -u root -p"redhat" -NBe "show databases")
################## send them to nas #######################
########## Send mail to acknowledge the scripts results ############
if [ $? = 0 ]; then
echo "Mysql Script excuted sucessfully on ${hostname} all data successfully dumped with name ${db}-week-${week}-${year}.sql.bz2 ${dumphost}" | mail -s " ${hostname} ${db}-week-${week}-${year}.sql.bz2 Mysqldump successfully" ${clientmailid}
else
echo "Mysql Script did not execute sucessfully on ${hostname} there is some error while script execution" | mail -s " ${hostname} ${db}-week-${week}-${year}.sql.bz2 Error while mysqldumping " ${clientmailid}
fi
By using the test $? at the end of your "do" loop you're not going to get the result of the mysqldump command, you're going to get the result of the end of the whole pipe.
Consider doing your dump, compress, and transfer in different stages and monitoring each stage.
for example (in pseudocode)
Code:
DUMPERROR=0
COMPRESSERROR=0
TRANSFERERROR=0
for db in listl; do
mysqldump blah blah blah > ${db}.sql
if [$? != 0 ] ; then
DUMPERROR=1
fi
bzip2 ${db}.sql
if [$? != 0 ] ; then
COMPRESSERROR=1
fi
scp ${db}.sql.bza user@host:/folder
if [$? != 0 ] ; then
TRANSFERERROR=1
fi
done
ERRORMESSAGE=""
if [$DUMPERROR = 1]; then
ERRORMESSAGE = "Error in the dumping stage"
fi
if [$COMPRESSERROR = 1]; then
ERRORMESSAGE = "${ERRORMESSAGE} Error in the compression stage"
fi
if [$TRANSFERERROR = 1]; then
ERRORMESSAGE = "${ERRORMESSAGE} Error in the transfer stage"
fi
if [$ERRORMESSAGE = ""]; then
echo "Success" | mail
else
echo "Failure $ERRORMESSAGE" | mail
fi
Like I say, just a rough code layout rather than proper scripting syntax!
Its not work...
Actually i want to monitor mysqld service with script which show me error when service not running as well as error in mysqldump commands..
so what error did you see, it is very obvious it will show some error the way it is used... but i can make eny comment only after having a look on the error.. you should have tested the command line before putting into the script.
Thanks for the reply..
actually i am getting success mail instead of error mail while my mysqld service stop..
there is must be error mail after script execusion..
i think mysqldump error code is 0 while mysqld service stop so i want some changes in my script in which it show me an error mail when mysqld service stop and i can get proper update mail of my mysql backup script..
Can we use this command for mysql service monitoring?
ps -ef | grep mysqld | grep -v grep;
Thank You
Last edited by jitendra.sharma; 09-04-2013 at 04:20 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.