cat ssh.sh
#!/bin/bash
#written by whitefox
function check_ip()
{
count=`echo $1 | awk -F "." '{print NF}'`
if [ $count -eq 4 ]
then
for var in `echo $1 |awk -F "." '{print $1,$2,$3,$4 }'`;
do
if [ $var -ge 0 -a $var -le 255 ]
then
continue
else
echo "$1 is error ip";
exit;
fi
done
else
echo "$1 is error ip";
exit;
fi
}
_IP1=$1
_IP2=$2
_COMMAND=$3
check_ip $1
check_ip $2
i=$(echo $_IP1 |awk -F "." '{print $4}')
n=$(echo $_IP2 |awk -F "." '{print $4}')
k=$(echo $_IP1 |awk -F "." '{print $1"."$2"."$3}')
for x in `seq $i $n `;do echo "$k.$x:" && ssh $k.$x "$_COMMAND" ;done
####################
example:
ssh.sh 172.2.18.3 172.2.18.10 "rm -rf /tmp/*"
阅读(714) | 评论(0) | 转发(0) |