一个Linux shell脚本模板

一个Linux shell脚本模板

#!/bin/sh
# Author:
# E-mail:
# Date:
# Description:


# 定义变量
basedir=''
if test -z "$basedir"
then
    basedir='/usr/local/mysql'
else
    bindir="$basedir/bin"
fi


# 执行信息
msg_functions='/etc/init.d/functions'
if test -f $msg_functions ; then
    . $msg_functions
else
    function action() {
        red='\033[31m'
        green='\033[32m'
        end='\033[0m'
        t='\t\t'
        case "$2" in
            'false')printf "${1}${t}[${red}FAILED${end}]\n";;
            'true')printf "${1}${t}[${green}  OK  ${end}]\n";;
        esac
    }
fi

# 定义环境变量
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
export PATH


# 定义本脚本的函数
multiple_arguments() {
    for arg do
        case "$arg" in
            --basedir=*)
                mysqld_basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                echo "$mysqld_basedir"
                ;;
            --datadir=*)
                echo "$arg"
                ;;
            --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
            --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
        esac
    done 
}

single_arguments() {
    case "$1" in
        'start')
            action "start" true
            ;;
        'stop')
            # Stop daemon. We use a signal here to avoid having to know the
            action 'stop stop stop stop stop stop sopt sojeweowejw jeoweiw jeiwoeijrewo jeiwo' false
            ;;
        *)
            basename=`basename "$0"`
            echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
            exit 1
            ;;
    esac
}


# 判断参数,执行函数
if [ $# -gt 1  ];then
    multiple_arguments "$@"
else
    single_arguments $1
fi


exit 0

执行示例

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值