Expect script throws "open(slave pty): bad file number" error
Hi all,
I have an Expect script that makes an ssh connection to a server, does a df -k on the remote server and exits. I repeat this on a number of servers. It works fine for a while then starts giving me this error :- open(slave pty): bad file number At this point, even if I try a ssh outside of my Expect script I get the same error. I have to close my cygwin and start it up again to be able to continue. I am running the expect script using Cygwin on Windows XP. I do know that this error is most likely if I do not close the processes spawned by my expect script properly. However, I do think that my script does close (or exit) properly. I am not sure what I am missing out. Can this be a problem with Cygwin ? I am a newbie so any help is much appretiated ! Here's my script : #!/usr/bin/expect proc report_failure {msg} { send_user "\n FAILURE: $msg \n" } proc report_failure_and_close {msg} { send_user "\n FAILURE: $msg \n" close; wait } proc handle_login {} { send "myPassword\r" while (1) { expect { -nocase "password:" { report_failure_and_close "Incorrect Password !" return } -re "(.*)\\$ $" { break } -re "(.*)> *$" { break } } } send "df -k\r" expect -re "(.*)\r" expect { -re "\\$ $" { expect * send "exit\r" wait } -re "> *$" { expect * send "exit\r" wait } } } spawn ssh -l user <IPADDRESS> expect { -re "(yes/no).*" { send "yes\n" expect -nocase "password:" { handle_login } } "Please type 'yes' or 'no':" { send "yes\n" expect "Password:" { handle_login } } -re "password: *" { handle_login } -re "^ssh:" { report_failure_and_close "Connection Failed for ushqseng11.eng.corio.com" } -re "Usage:" { report_failure_and_close "Usage Error !" } eof { report_failure "!!! Unexpected Error !!!" } timeout { report_failure_and_close "Connection time out" } } Thanks, KNut |
All times are GMT -5. The time now is 03:46 PM. |