-
解壓縮多個變量名的壓縮包
查看全部 -
for循環語法
查看全部 -
read -t 30 -p "please input a filename: " file?
查看全部 -
判斷file的值是否存在,為普通文件,為目錄文件等
查看全部 -
加減乘除計算器
查看全部 -
多分支if條件語句樣式
查看全部 -
多分支if條件語句寫法,
elif為關鍵詞
查看全部 -
#! /bin/bash
test=$(ps aux | grep httpd | grep -v grep)
#截取httpd進程,并把結果賦予變量test
if [ -n "$test" ]
#如果test的值不為空,則執行then中命令
????then
????????????echo " $(date) httpd is ok!" >> /tmp/autostart-acc.log
????else
????????/etc/rc.d/init.d/httpd start &> /dev/null
????????echo "$(date) restart httpd !!" >> /tmp/autostart-err.log
fi
看看linux 的crontab,例如
* */1 * * * /usr/local/apache/bin/apachectl restart查看全部 -
test是沒有返回值的,只能看$?來判斷他是否是正常執行.
if也是判斷$?來進行判斷的
查看全部 -
預定義變量$?
echo $?
返回0表示上一條命令成功執行
返回非0表示上一條命令未成功執行
查看全部 -
判斷文件類型格式:
-d 文件? ? ? 判斷該文件是否存在且是否為目錄文件,是為真
-e 文件? ? ? 判斷該文件是否存在,是為真
-f 文件? ? ? ?判斷該文件是否存在且是否為普通文件,是為真
查看全部 -
重要服務需要搭建監控服務器集群
安裝apache:yum install httpd
查看全部 -
-d 判斷該文件是否存在,并且是否為目錄文件(是目錄為真)
-e 判斷該文件是否存在(存在為真)
-f 判斷文件是否存在,并且是否為普通文件(是普通文件為真)
查看全部 -
shell多分支case語句
case $變量名 in
"值1")
????code1
;;
"值2"
????code2
;;
*)
code
;;
esac
#! /bin/bash
read -t 30 -p "please input yes or no" cho
cash $cho in
????"yes")
????????echo "you choose is yes"
????;;
????"no")
????echo "you choose is no"
????;;
????*)
????echo "your choose is error"
????;;
esac
查看全部 -
#判斷用戶輸入的是什么類型的文件
#!?/bin/bash read?-t?30?-p?"please?input?a?filename"?file if?[-z?"$file"] then echo?"error,please?input?a?filename" exit?1 elif?[!-e?"$file"] then echo?"your?input?is?not?a?file" exit?2 elif?[-f?"$file"] then echo?"this?is?a?file" exit?3 elif[-d?"$file"] then echo?"this?is?a?directory" exit?4 else echo?"this?is?a?other?file" fi
查看全部
舉報