测试登陆脚本
./test.sh -p 123 -P 3306 -h 127.0.0.1 -u root
#!/bin/sh
if [ $# -ne ];then
echo "USAGE: $0 -u user -p passwd -P port -h host"
exit
fi while getopts :u:p:P:h: name
do
case $name in
u)
mysql_user=$OPTARG
;;
p)
mysql_passwd=$OPTARG
;;
P)
mysql_port=$OPTARG
;;
h)
mysql_host=$OPTARG
;;
*)
echo "USAGE: $0 -u user -p passwd -P port -h host"
exit
;;
esac
done if [ -z $mysql_user ] || [ -z $mysql_passwd ] || [ -z $mysql_port ] || [ -z $mysql_host ]
then
echo "USAGE: $0 -u user -p passwd -P port -h host"
exit
fi echo $mysql_user $mysql_passwd $mysql_port $mysql_host
# 结果 root 123 3306 127.0.0.1