标签:ret lease default ini rest code sleep p12 mysql
开发mysql多实例启动脚本:
已知mysql多实例启动命令为:mysqld_safe–defaults-file=/data/3306/my.cnf &
停止命令为:mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown
要求:用函数,case语句、if语句等实现。
1 #!/bin/sh 2 [ -f /etc/init.d/functions ]&&. /etc/init.d/functions||exit 3 #Define Variables 4 Port=$1 5 Mysql_user=root 6 Mysql_sock=/data/${Port}/mysql.sock 7 Path=/application/mysql/bin 8 RETVAL=0 9 #Define Start Function 10 start() { 11 if [ ! -e "$Mysql_sock" ];then 12 /bin/sh $Path/mysqld_safe --defaults-file=/data/${Port}/my.cnf 2>&1 >/dev/null & 13 RETVAL=$? 14 if [ $RETVAL -eq 0 ];then 15 action "Starting $Port MySQL..." /bin/true 16 else 17 action "Starting $Port MySQL..." /bin/false 18 fi 19 else 20 echo "$Port MySQL is Running..." 21 fi 22 return $RETVAL 23 } 24 25 #Define Stop Function 26 stop() { 27 if [ ! -e "$Mysql_sock" ];then 28 echo "$Port MySQL is Stopped..." 29 else 30 read -p "Please Input $Port MySQL Password:" PWD 31 Mysql_pwd=$PWD 32 $Path/mysqladmin -u ${Mysql_user} -p${Mysql_pwd} -S /data/${Port}/mysql.sock shutdown 33 RETVAL=$? 34 if [ $RETVAL -eq 0 ];then 35 action "Stopping $Port MySQL..." /bin/true 36 else 37 action "Stopping $Port MySQL..." /bin/false 38 fi 39 fi 40 return $RETVAL 41 } 42 43 case "$2" in 44 start) 45 start 46 RETVAL=$? 47 ;; 48 stop) 49 stop 50 RETVAL=$? 51 ;; 52 restart) 53 stop 54 sleep 3 55 start 56 RETVAL=$? 57 ;; 58 *) 59 echo -e "USAGE:$0 {3306|3307|3308} {start|stop|restart}" 60 RETVAL=2 61 ;; 62 esac 63 exit $RETVAL
标签:ret lease default ini rest code sleep p12 mysql
原文地址:http://www.cnblogs.com/bidongweb/p/6961847.html