shell中的批处理脚本

批处理脚本

  • 检测教室中开启的所有主机,并抓取所有主机的值机名称和 ip的对应列表,把列表保存在 /mnt/ip_host.list 文件中。
#!/bin/bash
Auto_SSH()   
{
/usr/bin/expect <<-EOF
spawn ssh root@$1 hostname                   
expect {
"yes/no" { send "yes\r" ; exp_continue }        
"password" { send "redhat\r" }                
}
expect eof
EOF
}
for IP in {1..10}
do
        ping -c1 -w1 172.25.10.$IP &> /dev/null
        if [ "$?" -eq "0" ]
        then
                echo "`Auto_SSH 172.25.10.$IP | tail -n 1 | sed 's/^M//g'` A 172.25.10.$IP" >> /mnt/host
        fi
done

shell中的批处理脚本_第1张图片
执行结果:
在这里插入图片描述

你可能感兴趣的:(shell)