指令碼實現自動化安裝lamp&lnmp
阿新 • • 發佈:2018-11-07
#備註:前提是將lnmp和lnmp自動化指令碼寫好放在相應的路徑, 指令碼已寫好,請檢視我部落格中的 shell指令碼 專欄!
1 #!/bin/bash 2 #安裝lamp或者lnmp 3 4 path=/server/scripts #定義兩個指令碼路徑 5 [ ! -d "$path" ] && mkdir -p $path 6 7 cat <<EOF 8 1.[ install lamp ] 9 2.[ install lnmp ] 10 3.[ exit ] 11 please input num you want:12 EOF 13 14 read num 15 [[ ! $num =~ [1-3] ]] && { 16 echo "the num you input must be: 1 | 2 | 3 " 17 exit 4 18 } 19 20 [ $num -eq 1 ] && { #如果使用者選擇1,則執行lamp安裝命令 21 echo "start installing lamp..." 22 [ -x "$path/lamp.sh" ] && { #判斷指令碼是否可執行23 echo "$path/lamp.sh does not exist or can not be exec" 24 exit 1 25 } 26 source $path/lamp.sh 27 exit $? 28 } 29 30 [ $num -eq 2 ] && { #如果使用者選擇2,則執行lnmp安裝命令 31 echo "start installing lnmp..." 32 [ -x "$path/lnmp.sh" ] && { #判斷指令碼是否可執行33 echo "$path/lnmp.sh does not exist or can not be exec" 34 exit 1 35 } 36 source $path/lnmp.sh 37 exit $? 38 } 39 40 [ $num -eq 3 ] && { 41 echo goodbye! 42 exit 3 43 }