#!/bin/bash
centerip="centerip=123.60.81.8"
ftpip="ftpip=123.60.81.8"
onlineip="onlineip=123.60.156.191"
onlinetcpport="onlinetcpport=5086"
cmd1="root"
cmd2="root"
cmd3="cd /opt/jffs2/flash"
cmd4="sed -i '/^centerip/c$centerip' machineconfig.conf"
cmd5="sed -i '/^ftpip/c$ftpip' machineconfig.conf"
cmd6="sed -i '/^onlineip/c$onlineip' onlineconf.conf"
cmd7="sed -i '/^onlinetcpport/c$onlinetcpport' onlineconf.conf"
cmd8=" reboot -f"
while read -r ip; do
(sleep 2;
echo $cmd1;
sleep 2;
echo $cmd2;
sleep 2;
echo $cmd3;
sleep 2;
echo $cmd4;
sleep 2;
echo $cmd5;
sleep 2;
echo $cmd6;
sleep 2;
echo $cmd7;
sleep 2;
echo $cmd8;
sleep 5;) | telnet $ip
done < ips
#!/bin/bash
W="192.168.100." //定义变量
for ((i=1; i<=254; i++)) //循环1-254
do
IP="$W$i" //变量赋予得出完整IP
ping -c 3 -i 0.2 -W 3 $IP &> /dev/null //ping命令
if [ $? -eq 0 ];then //判断上条命令是否成功
echo "host $IP is up" && echo "host $IP is up" >> /root/ipup.txt //能ping通即在线
else
echo "host $IP is down" && echo "host $IP is down" >> /root/ipdown.txt//否则不在线
fi
done
筛选IP telnet是否要登录
# cat t.sh
#!/bin/sh
user="root"
pass="root"
#ip="192.168.1.98"
#ip="192.168.1.2"
for ip in `cat ips`
do
{
sleep 1
echo "$user";
sleep 2
echo "$pass";
sleep 2
exit
}|telnet $ip >ip.log ;cat ip.log |grep 'M28x login: root';
if [ $? = 0 ]; then
echo $ip >>ip1
else
echo $ip >>ip2
fi
done