批处理脚本:
检测教室中开启的所有主机,并抓取所有主机的主机名称和IP对应列表,把列表保存在/mnt/ip_host.list文件中
######lzy#####
#Create_time: 2020.09,02
#!/bin/bash
EXPECT() {
/usr/bin/expect << EFO
set timeout 3
spawn $1
expect {
"yes/no" { send "yes\r"; exp_continue }
"password" { send "westos\r" }
}
expect eof
EFO
}
for i in {1..10}
do
ping -c1 -w1 172.25.254.$i &>/dev/null &&{
echo 172.25.254.$i >> /mnt/ip_host.list
EXPECT "ssh root@172.25.254.$i hostname " | tail -n 1 >> /mnt/ip_host.list
}
done