LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-02-2012, 10:57 AM   #1
ShadowAce
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Rep: Reputation: Disabled
Expect script package return


I've run into an issue that I cannot resolve and Google seems to be no help, either. Hopefully, one of you gurus can help me out here:

I've been writing a bunch of expect scripts to perform functions on remote servers in our environment. Part of every script is the login process, which can get pretty tedious (it's a double login with multiple passwords).

While the login process works, it takes up a lot of space in each script. I'd like to push it off into a Tcl package, and it almost works. My new script now calls login $server and it will login to the remote server, but then it just hangs.

What I'm trying to do is similar to the following:

.
.
.
login $server

expect {
"#" {send "ls -ls /root\r"}
}
expect {
"#" {send "exit\r"}
}
.
.
.

My login script does NOT have an "expect eof", but it does have the following:

expect {
"#" {return}
}

However, somwhere between the end of the login $server line and the first expect, it just hangs. It does display the root prompt on the remote server, showing that the login was successful.

Is this an issue with process ids, threads, or something else?

How can I get my parent script to recognize the output from the login script to continue processing from the remote server?

Thanks!
 
Old 02-03-2012, 05:49 AM   #2
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 557

Rep: Reputation: 46
You need "ssh-keygen" to generate keys that you can share with the remote servers. Then you will need to do "ssh Demo@ExampleServer.com command_or_script" and it will return back from the server giving you the output of your command/script if it produces any.

First work on them and then let us know if you need more help. I am not familiar with Tcl so I do not know your codes above. But using the method I have specified above you can simply get a listing of files by issuing this command:

Code:
ssh Demo@ExampleServer.com ls -ltr /root
More Examples:

Code:
output=`ssh Demo@ExampleServer.com 'uptime; free'`
echo "System Health Info"
echo "$output"
 
Old 02-03-2012, 07:05 AM   #3
ShadowAce
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I appreciate you taking the time to reply. However, using ssh keys is not allowed in this environment.

I am familiar with the method you describe, and I would love to do it that way, but it is not politically feasible at this time.

I need to be able to log in, then be able to perform 1 or more commands. The "ls -ls" command in the OP was just an example. It needs to be able to perform a whole series of commands, if required.

Thank you!
 
Old 02-03-2012, 10:32 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
You can have ssh ask for the password just once, without needing to use keys:

Code:
# will ask for password here
ssh -NfM -o 'ControlPath=~/.ssh/%r@%h:%p.conn' "$HOST"

# uses existing connection, doesn't ask for password
ssh -o 'ControlPath=~/.ssh/%r@%h:%p.conn' ls -ls /root
ssh -o 'ControlPath=~/.ssh/%r@%h:%p.conn' another command
...

# close the connection
ssh -o 'ControlPath=~/.ssh/%r@%h:%p.conn' -O exit "$HOST"
 
Old 02-03-2012, 11:14 AM   #5
ShadowAce
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Talking

That would be fine if I didn't have to work on several hundred different remote servers.
 
Old 02-07-2012, 08:31 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Hmm, I guess there aren't many expect experts on this forum, it might be easier to help if you could give a small self-contained example to demonstrate the problem.
 
  


Reply

Tags
expect, ssh


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
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM
Can expect return control of a spawned process to a shell script? duffrecords Programming 4 04-28-2010 03:33 PM
return value of expect script .. shriyer Linux - Software 9 07-10-2009 05:06 PM
expect return failes Ricio Programming 14 07-22-2008 10:45 AM


All times are GMT -5. The time now is 04:02 AM.

Main Menu
Advertisement
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