shell学习二十三--case语句编写mysql启动脚本

前端之家收集整理的这篇文章主要介绍了shell学习二十三--case语句编写mysql启动脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
六、例子:开发@R_403_198@单实例或者多实例启动脚本 已知@R_403_198@多实例启动命令为: @R_403_198@d_safe --deafaults-file=/data/3306/my.cnf & 停止命令 @R_403_198@admin -u root -p123 -S /data/3306/@R_403_198@.sock shutdown 请完成@R_403_198@单实例或者多实例启动脚本编写。 要求:用函数、case语句等实现。 [root@node01 day10]# vi start_db.sh #!/bin/sh # chkconfig: 2345 35 67 # description: start rsync and stop rsync scripts. . /etc/init.d/functions path=/usr/bin/ pass=123 user=root function usage(){ echo "$0 {start|stop|restart}" exit 1 } [ $# -ne 1 ] && usage function start_@R_403_198@(){ $path/@R_403_198@d_safe --user=@R_403_198@ >/dev/null 2>&1 & if [ $? -eq 0 ] then action "start @R_403_198@" /bin/true else action "start @R_403_198@" /bin/false fi } function stop_@R_403_198@(){ @R_403_198@admin -u$user -p$pass shutdown >/dev/null 2>&1 if [ $? -eq 0 ] then action "stop @R_403_198@" /bin/true else action "stop @R_403_198@" /bin/false fi } case "$1" in start) start_@R_403_198@ RETVAL=$? ;; stop) stop_@R_403_198@ RETVAL=$? ;; restart) stop_@R_403_198@ sleep 2 start_@R_403_198@ RETVAL=$? ;; *) usage esac [root@node01 day10]# sh start_db01.sh start start @R_403_198@ [ OK ] [root@node01 day10]# sh start_db01.sh stop stop @R_403_198@ [ OK ] [root@node01 day10]# sh start_db01.sh restart stop @R_403_198@ [Failed] start @R_403_198@ [ OK ] [root@node01 day10]# @R_403_198@ -uroot -p123 Welcome to the @R_403_198@ monitor. Commands end with ; or \g. Your @R_403_198@ connection id is 1 Server version: 5.1.73 Source distribution Copyright (c) 2000,2013,Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. @R_403_198@>

猜你在找的Bash相关文章