shell脚本:MySQL启动简易脚本
2015-10-21 10:12
441 查看
shell脚本编写MySQL建议简易启动脚本,练习使用变量,函数,case语句等知识;
执行结果如下图所示:
本文出自 “模范生的学习博客” 博客,请务必保留此出处http://mofansheng.blog.51cto.com/8792265/1704762
[root@localhost baby]# cat mysql_function.sh #!/bin/bash . /etc/init.d/functions path=/usr/local/mysql/bin/ function usage(){ echo "$0 {start|stop|restart}" exit 1 } [ $# -ne 1 ] && usage function_mysql_start(){ $path/mysqld_safe --user=mysql &>/dev/null & if [ $? -eq 0 ] then sleep 5 action "start mysql" /bin/true else action "start mysql" /bin/false fi } function_mysql_stop(){ $path/mysqladmin -uroot shutdown &>/dev/null if [ $? -eq 0 ] then action "stop mysql" /bin/true else action "stop mysql" /bin/false fi } function_mysql_restart(){ function_mysql_stop sleep 3 function_mysql_start } case $1 in start) function_mysql_start ;; stop) function_mysql_stop ;; restart) function_mysql_restart ;; *) printf "Usage:$0 {start|stop|restart}\n" esac
执行结果如下图所示:
本文出自 “模范生的学习博客” 博客,请务必保留此出处http://mofansheng.blog.51cto.com/8792265/1704762
相关文章推荐
- powershell常用
- shell awk 检查程序是否执行
- shell脚本之——dirname
- 通过Xshell上传下载文件
- shell 学习笔记 (二)
- awk使用shell中的变量
- Spark shell脚本
- Linux学习笔记---shell脚本基础
- linux及shell常用命令及遇到的问题集合
- -bash: /bin/tar: Argument list too long
- Linux下profile environment bashrc的区别
- shell编程-创建函数
- 使用Remote PowerShell远程管理Lync
- No such file or directory; did you install phantomjs? php shell_exec报错的解决
- shell命令之(二)rsync的艺术
- bash之条件测试if/else
- bash脚本编写基础
- Sed替换行和字符shell
- python执行linux的shell命令
- 《Linux Shell》笔记之dos2unix