打印选择菜单,一键安装Web服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印选择菜单,一键安装Web服务相关的知识,希望对你有一定的参考价值。

打印选择菜单,一键安装Web服务:

[[email protected]]# sh menu.sh 
    1.[install lamp]
    2.[install lnmp]
    3.[install mysql]
    4.[install php]
    5.[exit]
    pls input the num you want:

要求:

1、当用户输入1时,输出“startinstallinglamp.”然后执行/server/scripts/lamp.sh,脚本内容输出"lampis installed"后退出脚本;

2、当用户输入2时,输出“startinstallinglnmp.”然后执行/server/scripts/lnmp.sh输出"lnmpis installed"后退出脚本;

3、当用户输入2时,输出“startinstallingmysql.”然后执行/server/scripts/mysql.sh输出"mysql installed"后退出脚本;

4、当用户输入2时,输出“startinstallingphp.”然后执行/server/scripts/php.sh输出"php installed"后退出脚本;

5、当输入3时,退出当前菜单及脚本;

6、当输入任何其它字符,给出提示“Input error”后退出脚本。

7、要对执行的脚本进行相关条件判断,例如:脚本是否存在,是否可执行等。

解答:

#!/bin/bash
RED_COLOR=‘\E[1;31m‘
GREEN_COLOR=‘\E[1;32m‘
YELLOW_COLOR=‘\E[1;33m‘
BLUE_COLOR=‘\E[1;34m‘
PINK_COLOR=‘\E[1;35m‘
RES=‘\E[0m‘
cat <<EOF   要打印的菜单
1.[install lamp]
2.[install lnmp]
3.[install mysql]
4.[install php]
5.[exit]
EOF
read -p"pls input the num you want:" a   请输入一个参数
case$ain
1)
  echo -e "$BLUE_COLOR startinstalling lamp $RES"    给输出的内容加上颜色
  lampScripts=/server/scripts/lamp.sh
 [-f$lampScripts] && sh $lampScripts|| exit1   判断要执行的lamp文件是否存在
 ;;
 2)
  echo -e "$PINK_COLOR startinstalling lnmp $RES"
  lnmpScripts=/server/scripts/lnmp.sh
  [-f$lnmpScripts] && sh $lnmpScripts|| exit2
 ;;
 3)
  echo -e "$GREEN_COLOR startinstalling mysql $RES"
  mysqlScripts=/server/scripts/mysql.sh
  [-f$mysqlScripts] && sh $mysqlScripts|| exit3
 ;;
 4)
 echo-e "$PINK_COLOR startinstalling php $RES"
 phpScripts=/server/scripts/mysql.sh
  [-f$phpScripts] && sh $phpScripts|| exit4
  ;;
 *)
  echo -e "$RED_COLOR input error $RES"
esac




本文出自 “每天一小步” 博客,请务必保留此出处http://fenyuer.blog.51cto.com/11265169/1944999

以上是关于打印选择菜单,一键安装Web服务的主要内容,如果未能解决你的问题,请参考以下文章

使用shell打印菜单,一键安装Web应用

shell-菜单自动化软件部署

一键式菜单自动化部署LA(N)MP脚本

HTML代码片段

HTML代码片段

阿里云Linux一键安装web环境使用教程