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

前端之家收集整理的这篇文章主要介绍了shell学习二十三--case语句编写mysql启动脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
六、例子:开发MysqL单实例或者多实例启动脚本 已知MysqL多实例启动命令为: MysqLd_safe --deafaults-file=/data/3306/my.cnf & 停止命令 MysqLadmin -u root -p123 -S /data/3306/MysqL.sock shutdown 请完成MysqL单实例或者多实例启动脚本编写。 要求:用函数、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_MysqL(){ $path/MysqLd_safe --user=MysqL >/dev/null 2>&1 & if [ $? -eq 0 ] then action "start MysqL" /bin/true else action "start MysqL" /bin/false fi } function stop_MysqL(){ MysqLadmin -u$user -p$pass shutdown >/dev/null 2>&1 if [ $? -eq 0 ] then action "stop MysqL" /bin/true else action "stop MysqL" /bin/false fi } case "$1" in start) start_MysqL RETVAL=$? ;; stop) stop_MysqL RETVAL=$? ;; restart) stop_MysqL sleep 2 start_MysqL RETVAL=$? ;; *) usage esac [root@node01 day10]# sh start_db01.sh start start MysqL [ OK ] [root@node01 day10]# sh start_db01.sh stop stop MysqL [ OK ] [root@node01 day10]# sh start_db01.sh restart stop MysqL [Failed] start MysqL [ OK ] [root@node01 day10]# MysqL -uroot -p123 Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL 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. MysqL> 原文链接:https://www.f2er.com/bash/389596.html

猜你在找的Bash相关文章