LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-24-2004, 12:24 PM   #1
KNut
LQ Newbie
 
Registered: Feb 2004
Location: Silicon Valley, CA, USA
Posts: 1

Rep: Reputation: 0
Question 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"bad interpreter : no such file or directory" when configure "flex" acer_peri Linux - Software 10 11-10-2010 01:19 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
error in 6.13 binutils~ expect -c"spawn ls" sharmashikha Linux From Scratch 1 06-21-2005 11:53 AM
Suse 9.2 -KDE boot error "re: io-slave" jtheb Suse/Novell 3 02-22-2005 10:47 PM
Compiling KDE 3.2.0 - "Can't open perl script "/dcopidlng/kalyptus" linuxgamer09483 Linux - Software 3 04-09-2004 08:25 PM


All times are GMT -5. The time now is 09:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration