ping 几个IP 地址,看是否host still up.
-
#! /usr/bin/env sh
-
set -x
-
set +x
-
BINARY="$(basename $0)[$$]"
-
echo "$BINARY"
-
DIRNAME="$(dirname $0)"
-
echo "$DIRNAME"
-
echo $PWD
-
-
IP_HEADER="10.32.134."
-
ip_range=(32 34 35 36 37 38 46 47 48 49)
-
length=${#ip_range[@]}
-
for (( i=0;i<$length;i++ ));do
-
ping -c 1 $IP_HEADER${ip_range[$i]} 2>&1 > /dev/null
-
#for i in ${ip_range[@]};do
-
# ping -c 1 $IP_HEADER$i 2>&1 > /dev/null
-
if [[ $? -ne 0 ]];then
-
echo $IP_HEADER$i is not respond to ping
-
fi
-
done
-
echo "all system are fine"
第二个脚本,使用expect 远程登陆看机器内存,我在网上找了个别人写好的expect 的函数来用,很不错。
-
#! /usr/bin/env sh
-
-
auto_smart_ssh () {
-
expect -c "set timeout -1;
-
spawn ssh -o StrictHostKeyChecking=no $2 ${@:3};
-
expect {
-
*assword:* {send -- $1\r;
-
expect {
-
*denied* {exit 2;}
-
eof
-
}
-
}
-
eof {exit 1;}
-
}
-
"
-
return $?
-
}
-
read -p "password:" pass
-
IP_HEADER="10.32.134."
-
ip_range=(32 34 35 36 37 38 46 47 48 49)
-
ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
-
-
for i in ${ip_range[@]};do
-
mem=`auto_smart_ssh $pass $ssh_opts $IP_HEADER$i "free -m" |awk '/Mem:/{print $2}'`
-
echo "$IP_HEADER$i has $mem memory"
-
done
使用sshpass ssh登陆:
-
sshpass -p'YOURPASSWORD' ssh root@YOURIP
阅读(1898) | 评论(0) | 转发(0) |