标签:shell
打印选择菜单,按照选择一键安装不同的Web服务。
示例菜单:
[root@oldboy scripts]# shmenu.sh
1.[install lamp]
2.[install lnmp]
3.[exit]
pls input the num you want:
要求:
1、当用户输入1时,输出“startinstalling lamp.提示”然后执行/server/scripts/lamp.sh,脚本内容输出"lampis installed"后退出脚本,工作中就是正式lamp一键安装脚本;
2、当用户输入2时,输出“startinstalling lnmp.提示” 然后执行/server/scripts/lnmp.sh输出"lnmpis installed"后退出脚本,工作中就是正式lnmp一键安装脚本;
3、当输入3时,退出当前菜单及脚本;
4、当输入任何其它字符,给出提示“Input error”后退出脚本;
5、要对执行的脚本进行相关的条件判断,例如:脚本文件是否存在,是否可执行等判断,尽量用上前面讲解的知识点。
#!/bin/bash
path=/server/scripts
[ ! -d "$path" ] && mkdir -p $path
#memu
cat <<END
1.[install lamp]
2.[install lnmp]
3.[exit]
pls input the num you want:
END
read num
expr $num + 1 &>/dev/null
[ $? -ne 0 ] &&{
echo "the num you input must be {1|2|3}"
exit 1
}
case $num in
1)
echo "start installing lamp"
sleep 3
[ -x "$path/lamp.sh" ]||{
echo "$path/lamp.sh does not exist or can not be exec."
exit 1
}
$path/lamp.sh #脚本文件
exit $?
;;
2)
echo "start installing LNMP"
sleep 3
[ -x "$path/lamp.sh" ]||{
echo "$path/lnmp.sh does not exist or can not be exec."
exit 1
}
$path/lnmp.sh #脚本文件
exit $?
;;
3)
echo bye.
exit 3
;;
*)
echo "the num you input must be {1|2|3}"
echo "Input ERROR"
exit 4
esac标签:shell
原文地址:http://wangwh.blog.51cto.com/12427110/1924705