打印選擇菜單,一鍵安裝Web服務

打印選擇菜單,一鍵安裝Web服務:

[root@oldboyscripts]# 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 $a in
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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章