-
#!/bin/bash
#輸出列表,1,2,3
echo "上苙丞 ,please :1"
echo "八星聯(lián) ,please :2"
echo "掟上今日子,please:3"
#讀取dec這個變量
read -t 30 -p "input you like detective,please:" dec
#多分支case語句選擇輸入出
case "$dec" in
? ? ? ? "1")
? ? ? ? echo "you choice 上苙丞."
? ? ? ? ;;
? ? ? ? "2")
? ? ? ? echo "you choice 八星聯(lián)."
? ? ? ? ;;
? ? ? ? "3")
? ? ? ? echo "you choice 掟上今日子."
? ? ? ? ;;
? ? ? ? *)
? ? ? ? echo "input right informaition,please!"
? ? ? ? ;;
esac
~
查看全部 -
沒有裝apache服務,有tomcat服務,改用tomcat服務測試
#!/bin/bash
#截取tomcat進程,并把結果賦予變量test
test=$( ps aux | grep tomcat | grep -v grep | grep "/usr/share/tomcat" | cut -d "=" -f 2 )
#判斷test是否為空,為空則執(zhí)行then中的命令
if [ -n "$test" ];then
#把tomcat服務運行狀態(tài)重定向指定的log日志? ??
?echo "$(date) this tomcat is online." >> /tmp/tomcat_is_ok.log
else
#tomcat服務沒起來,所以要啟動tomcate服務,重啟后的命令傳到黑洞?
????/usr/share/tomcat/bin/startup.sh &> /dev/null
#把tomcat重啟后的狀態(tài)重定向指定的log日志? ? ? ??
????echo "$(date)this tomcat is restart!" >> /tmp/tomcat_is_restart.log
fi
查看全部 -
#!/bin/bash
#用讀取鍵盤命令等待30秒,顯示提示語句,并把鍵盤輸入的文件或目錄賦值給dir變量
read -t 30 -p "please input a dir: " dir
#用if語句判斷輸入的dir變量是否為目錄
if [ -d $dir ];then
#如果是目錄,即顯示輸入的是目錄
? ? ? ? echo "input is a dir."
else
#如果不是目錄,即顯示輸入的不是目錄
? ? ? ? echo "input is not dir."
fi
查看全部 -
#!/bin/bash
#通過awk和cut命令把根目錄下的磁盤空間占用量的數(shù)值截取出來,賦值到變量test1
test1=$(df -h | grep? centos-root | awk '{ print $5 }' | cut -d "%" -f 1)
#通過awk命令把包含此目錄centos-root和占用百分比的值,賦值到變量test1
test2=$(df -h | grep "centos-root" | awk '{print $1, $5}')
#用if命令跟90作運算符比較
if [ "$test1" -gt 90 ];then
#如果大于90,則輸出你的硬盤空間滿了,輸出test2的值
? ? ? ? echo "your Disk space will full!$test2"
else
#否則,則輸出你的硬盤空間空閑,輸出test2的值? ? ? ?
?????echo "your Disk space is empty!$test2"
fi
查看全部 -
#!/bin/bash
#用env結合cut命令查找當前登錄用戶,并把當前用戶賦值給test變量。
test=$( env | grep USER | cut -d "=" -f 2 )
#用if判斷語句來判斷變量test的值是否是root用戶,因為是字符串,所以需要用==來判斷。
?if [ "$test" == "root" ];then??
#如果判斷為真,則輸出以下語句,說明當前登錄用戶是root.
????echo "this is user is root."#如果判斷為假,則輸出以下語句,說明當前登錄用戶不是root.
else??
????echo "this is user isn't root."
fi
查看全部 -
env查看環(huán)境變量,可以查看當前登錄用戶。
whoami可以查看當前登錄用戶,但是不準,如果不是用-來切換用戶的話。
查看全部 -
等待30秒等待用戶輸入內容,輸入后保存到變量dir
read -t 30 -p "please input a dir:" dir
查看全部 -
vi 文件名 #編寫shell腳本文件,第一行代碼以#!/bin/bash開頭
根據(jù)關鍵詞讀取文件內容:cat filename | grep keywork
排除關鍵詞:grep -v keywork
根據(jù)關鍵詞":"號截取內容:cut -d ":"
查看全部 -
#!/bin/bash read?-p?"number1:?"?num1 read?-p?"number2:?"?num2 read?-p?"ope:?"?ope if?[?-n?"$num1"?-a?-n?"$num2"?-a?-n?"$ope"?] ????????then ????????????????test1=$(echo?$num1?|sed?'s/[0-9]//g') ????????????????test2=$(echo?$num2?|sed?'s/[0-9]//g') ????????else ????????????????echo?"enter?number?is?null,try?again" ????????????????exit?12 fi if?[?-z?"$test1"?-a?-z?"$test2"?] ????????then ????????????????echo?"Please?enter?a?valid?value" ????????????????exit?10 fi if?[?"$ope"=='+'?] ????????then ????????????????sum=$((?$num1?+?$num2?)) elif?[?"$ope"=='-'?] ????????then ????????????????sum=$((?$num1?-?$num2?)) elif?[?"$ope"=='*'?] ????????then ????????????????sum=$((?$num1?*?$num2?)) elif?[?"$ope"=='/'?] ????????then ????????????????sum=$((?$num1?/?$num2?)) else ????????echo?"Please?enter?a?valid?symbol" ????????exit?11 fi echo?"$num1?$ope?$num2?=?$sum"
查看全部 -
多分枝if條件語句
查看全部 -
判斷apache是否啟動
查看全部 -
rhgtrhyt查看全部
-
hyhth查看全部
-
uiyjuj查看全部
-
dfhrhr查看全部
舉報