Shell script : MySQL Backup from remote server

#!/bin/sh
#install mailutils as to send mail
# $apt-get install mailutils
#-----------------
#Specify the path to save your dump file
path='/temp/dump/'
#-----------------
#get system IP's to know on which system the script is running
#it will help full when you have more number server and you dont know on from which server the script running and throwing alert
systemip=`ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'`
#-----------------
#specify mail id's seperated by ","
mailids='user1@example.com,user2@example.com'
#-----------------
#(date +%m_%y_%d_) will be used to separate the compress files on month basis.
#please specify your remote server mysql [user] and [password] and make sure the mysql user name has remote host access permission
#syntax mysqldump -u [usrname] -p[password] -h www.example.com [databasename]
if mysqldump -u user -ppassword -h example.com database > $path$(date +%m_%y_%d_)file.sql; then
#will download the .sql from remote host
if zip $path$(date +%m_%y_).zip $path$(date +%m_%y_%d_)file.sql; then
#will compress to .sql into .zip
if rm $path$(date +%m_%y_%d_)file.sql; then
#will remove the dump file
exit 1
else
echo "Unable to remove .sql file. \n hi" | mail -s "Subject" $mailids
exit 1
fi
else
echo "Unable to comperes in mysql zip. " | mail -s "Subject" $mailids
exit 1
fi
else
echo "Error in connecting mysql. \nIP of script running system: \n"$systemip | mail -s "Subject" $mailids
exit 1
fi