用途:需要查詢多台伺服器的特定Nfs mount point 是否可以正常掛載 .
方法:需準備兩支程式(chk_nfs.sh ,kill_rshtimeout.sh )及機器清單(serverlist.txt , 清單檔名當然可以自由取 )
範例:
假設我們想去查詢每一台伺服器是否都可以mount 到 /home/oratest
例如以下的伺服器清單存成serverlist.txt :
oraserver1
oraserver2
aplnx1
apsun1
....略
語法示範:
chk_nfs.sh serverlist.txt /home/oratest
---> 去掃瞄所有在 serverlist.txt 清單的伺服器 是否可以掛載 /home/oratest
說明:
(1) 第一支:是主程式,名為chk_nfs.sh,主要是用來rsh 至每一台Server,查詢該Server是否可以 Mount /home/oratest .
( 引用者請註明本出處)
!/bin/sh
serverlist=$1
checkdir=$2
set `cat ./$serverlist`
while [ $# -gt 0 ]
do
echo "$1 ---------------------------------------: "
nohup ./kill_rshtimeout.sh $1 mount $checkdir & ---> 這是另一支外部程式
rsh $1 cd $checkdir
nohup ./kill_rshtimeout.sh $1 df $checkdir & ---> 這是另一支外部程式
rsh $1 df $checkdir
shift 1
done
(2) 第二支: 在第一支Script 中有呼叫本程式,名為 kill_rshtimeout.sh
這一支才是本案例的精華所在
這是因為系統在Rsh 至每一台機器過程中,可能對方機器因素導致RSH 不通或卡住,
當然我們不能在終端機前枯等RSH 自然Timeout ,這會等到天花地老海枯石爛的!
這時候就需要這支Script 來強制中斷RSH Connection(砍掉RSH Process) ,
繼續進行下一台機器的偵測檢查,
並且會把不通的Server 記錄在Log 之中,LOG 會產生在該Script 同一層目錄中
default Rsh Timeout 設為 10 秒,可以自行更改。
( 引用者請註明本出處)
#!/bin/sh
function=$2
servername=$1
dirname=$3
tree=`echo $dirname | cut -d/ -f3 `
command1="rsh $servername cd $dirname"
command2="rsh $servername df"
sleep 10
if [ $function = mount ]
then
result=$tree.nfs-fail.txt
cat /dev/null > $result
flag1=`ps -ef |grep "$command1" |grep -v grep |awk -F" " '{print $2}' |wc -l`
if [ $flag1 -gt 0 ]
then
set `ps -ef |grep "$command1" |grep -v grep |awk -F" " '{print $2}'`
echo "$servername : mount NAS1 fail" >> $result
while [ $# -gt 0 ]
do
kill -9 $1
shift 1
done
exit 0
fi
fi
if [ $function = df ]
then
result=$tree.nfs-fail.txt
cat /dev/null > $result
flag2=`ps -ef |grep "$command2" |grep -v grep |awk -F" " '{print $2}' |wc -l`
if [ $flag2 -gt 0 ]
then
set `ps -ef |grep "$command2" |grep -v grep |awk -F" " '{print $2}'`
echo "$servername : df hang" >> $result
while [ $# -gt 0 ]
do
kill -9 $1
shift 1
done
fi
fi