I don't know where to go for this question... I've found lots of suggestions on Google and tried most of them but none work. So I'm coming to the Ubuntu community in hopes of finding an Expect expert.
My Expect script is designed to telnet to every address in my /16 network. Some addresses will respond, some won't, that's ok. The script runs and does what I want it to, but for some reason it stops after 1,016 connections. So I'm thinking that I'm not closing something properly but I don't know what else to do. I did a "ps -A | grep telnet" while it's running and all my telnet sessions say "<defunct>".
The error I receive is:
NotifierThreadProc: could not create trigger pipe
parent: sync byte write: broken pipe
Here's my code (shortened a bit for readability):
Code:
#!/usr/bin/expect
set timeout 1
set SITE 1
set HOST 1
while {$SITE < 255 } {
while {$HOST < 255 } {
spawn telnet 10.0.$SITE.$HOST
# this just displays the spawn ID for troubleshooting
set netip $spawn_id
send_user $netip\n
expect {
# no need to process further if Cisco switch is detected
timeout {send eof; send_user "TIMED OUT\n"; close}
"Username:" {
expect "'^]'."
send_user "CISCO SWITCH\n"
close
}
# here's what I'm looking for, a login for a UPS
"User Name :" {
send AAA\r
expect "Password :"
send P4SS\r
expect {
# if User Name is requested twice in a row, then the password is bad
"User Name :" {
send eof
send_user "BAD PASSWORD\n"
close
}
"Log" {
sleep .1
send 3\r
(do more menu navigation and make changes in here... all this works fine)
expect "Log"
sleep .1
send 4\r
expect "foreign host."
close
}
}
}
}
set HOST [expr $HOST+1]
}
set HOST 1
set SITE [expr $SITE+1]
}
Ubuntu 14.04
Expect 5.45