码迷,mamicode.com
首页 > 系统相关 > 详细

shell-菜单自动化软件部署

时间:2017-05-11 22:20:58      阅读:279      评论:0      收藏:0      [点我收藏+]

标签: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-菜单自动化软件部署

标签:shell

原文地址:http://wangwh.blog.51cto.com/12427110/1924705

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!