Created
September 14, 2016 08:33
-
-
Save staugur/c66e505bc6d7559ae035f9a8aaa0cacb to your computer and use it in GitHub Desktop.
Shell 入参类型预检测
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
检测Sdp入参,用户名是否冲突、时间期限是否符合正整数、服务|文件类型是否在范围、邮箱是否符合格式等,并将错误信息写入日志。 | |
1).用户名若发生冲突,同个用户需要多个服务当前版本必须多次以不同用户名执行; | |
2).使用时间不限,至少1个月; | |
3).服务类型:nginx、httpd、tomcat、mysql、mongodb、redis、memcached; | |
4).文件类型:若为web类型可支持ftp、svn,若为app类型默认无; | |
5).邮件提醒:部署成功后会发给用户一封服务信息邮件(确保不在垃圾邮件中),包括服务到期、服务续费、服务停止提醒。 | |
#判断入参及入参要求是否符合。 | |
if [ "$#" = 5 ]; then | |
#判断用户是否存在 | |
if [ -d ${INIT_HOME}/$1 ]; then | |
echo -e "\033[31mThe user already exists\033[0m" 2>&1 | |
echo "${PreciseTime} $1 $5 ErrAction:\"The user already exists\"" >> $Errlog | |
exit 1 | |
fi | |
#判断时间格式 | |
if [[ "$2" =~ ^[0-9]+$ ]]; then | |
: | |
else | |
echo "第二个参数要求为正整数,单位为月!" | |
echo "${PreciseTime} $1 $5 ErrAction:\"使用时间参数错误\" " >> $Errlog | |
exit 1; | |
fi | |
#判断服务类型 | |
if echo "${services[@]}" | grep -w $3 &> /dev/null ;then | |
: | |
else | |
echo -e "\033[31m不支持的服务类型\033[0m" 2>&1 | |
echo "${PreciseTime} $1 $5 ErrAction:\"不支持的服务类型\"" >> $Errlog | |
exit 1 | |
fi | |
#判断文件代码类型 | |
if [ $4 = "svn" ] || [ $4 = "ftp" ] || [ $4 = "-" ] || [ $4 = "null" ];then | |
: | |
else | |
echo -e "\033[31m不支持的代码类型\033[0m" 2>&1 | |
echo "${PreciseTime} $1 $5 ErrAction:\"不支持的代码类型\"" >> $Errlog | |
exit 1 | |
fi | |
#判断邮箱格式 | |
if [[ `echo $5 | sed -r '/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/!d'` == "" ]]; then | |
echo "邮箱格式不正确!" | |
echo "${PreciseTime} ${init_user} ${user_email} ErrAction:\"邮箱格式不正确\" " >> $Errlog | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment