Reputation: 2279
I am using expect module for performing a task.
This is sample of my code
foreach temp $list {
spawn -X $temp
while {1} {
expect {
eof {break}
"password {send "password\r"}
"\]" {send "exit\r"}
}
}
}
The script is getting break after 1071 counter. with the error
too many programs spawned? could not create pipe: too many file open while executing "spawn ssh -X ..."
Upvotes: 0
Views: 3552
Reputation: 137757
There's a relatively low limit on the number of simultaneous programs that can be spawned at once (it depends on how many virtual terminals your system supports; I'm actually surprised that you got to over 1000 there…) so you need reap those old programs once you're done with them (Expect does reap everything on exit, but here it matters because you're running out much sooner than that). What's more, the limit will depend on what else is going on on your system, as virtual terminals are actually a system-global resource…
To reap the old program once you're done with it, add wait
to the end of your loop (assuming you don't want the subprocess to continue past the end of the loop, of course) to get this:
foreach temp $list {
spawn -X $temp
while {1} {
expect {
eof {break}
"password" {send "password\r"}
"\]" {send "exit\r"}
}
}
wait ;#### <<<<<----- THIS!!!
}
You might also want to take a look at exp_continue
, as that lets you rewrite to get rid of the explicit while
(and also the need to explicitly handle the EOF condition) and overall make your code simpler:
foreach temp $list {
spawn -X $temp
expect {
"password" {send "password\r"; exp_continue}
"\]" {send "exit\r" ; exp_continue}
}
wait
}
Upvotes: 4
Reputation: 359
Sounds like a similar problem I am having. Have you tried ulimit -a and checked either processes or files?
Upvotes: 0