1. 程式人生 > >遠端監控web是否正常輸入網址進行判斷

遠端監控web是否正常輸入網址進行判斷

遠端監控web是否正常
要求:
1)使用傳參方式
2)判斷引數是正確
3)有輸出提示
指令碼實踐
#!/bin/sh
#引用系統函式
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
#判斷輸入的引數是否正確
usage(){
echo “USAGE:$0 url”
exit 1
}
#定義吧變數
RETVAL=0
funCheckUrl(){
wget -T 10 --spider -t 2 KaTeX parse error: Expected 'EOF', got '&' at position 3: 1 &̲>/dev/null …

?
if [ $RETVAL -eq 0 ];then
action “$1 url” /bin/true
else
action “$1 url” /bin/false
fi
return $RETVAL
}
main(){
if [ $# -ne 1 ];then
usage
fi
funCheckUrl 1 R E T V
A L = 1 RETVAL=
?
return $RETVAL
}
main $*
要點:
指令碼名稱叫test.sh 入參三個: 1 2 3
執行test.sh 1 2 3後
$*為"1 2 3"(一起被引號包住)
[email protected]為"1" “2” “3”(分別被包住)
$#為3(引數數量)

2>/dev/null 錯誤定向空

/dev/null 2>&1相等&>/dev/null 正確錯誤都定向空