您好,我想制作一个脚本来测试ping并将输出放入文件中。感谢您的所有帮助。
#!/usr/bin/expect -f
set IPaddress [lindex $argv 0]
set fildes [open "ip.txt" r]
set output [open "out.txt"]
while {[gets $fildes ip ] != -1} {
set timeout 5
spawn ping -c 3 $ip
expect {
" 0%" {puts "$ip Is Up"}
" 100%" {puts "$ip Is Down"}
}
}
我想把看跌期权“ $ ip Is Up”和$ ip Down写入文件out.txt然后我要计算有多少IP启用和有多少IP停用。喜欢:
30 Ips Is up
20 Ips Is down
我也想要out.txt
中的计数。
现在工作,我只需要添加“ w”,这是我的代码更新:
set IPaddress [lindex $argv 0]
set fildes [open "ip.txt" r]
set output [open "out.txt" w]
while {[gets $ fildes ip]!= -1} {
set timeout 5
spawn ping -c 3 $ip
expect {
" 0%" {puts $output "$ip Is Up"}
" 100%" {puts $output "$ip Is Down"}
}
}