一个Linux shell脚本模板
#!/bin/sh
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')
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 [ $
multiple_arguments "$@"
else
single_arguments $1
fi
exit 0
执行示例
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201222224911507.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2h1X3poZV9rYW4=,size_16,color_FFFFFF,t_70)