Ruby Expect

R

Rich Masci

I have a expect scripts that I use to get from system to system, and
would like to translate them into Ruby. These scripts I use to ssh into
a system, setup environment variables and aliases that then turn over
control to me.. My scripts are usually a lot longer bug basically in
Expect:

set host [lindex $argv 0]
set password "myp@$$"
set prompt "
spawn ssh $host
expect -re "\[P|p]asssword
send "$password\r"
expect $prompt
send "<custom environment variables and aliases>\r"
interact

Invoking a script like this with a hostname or ip address will log me
into that system, and customize it for my liking without making changes
to the server it's self. Expect also allows you to log your session
(not shown in above example) so two months later you can pull your log
file and see how you ran a given command.

Is there any Ruby extension that gives me the same functionality? The
book 'Exploring Expect' has a chapter on using the expect library with
Ruby or other C programs, has anyone attempted to use his library with
Ruby? I also see that ruby tk has a way of wrapping tcl commands, and in
irb I've actually loaded the Expect extension for TCL, but I've no idea
how to use it.
 
B

Brian Candler

Rilindo said:
Hi Richard! Nice to see you!

For just logging in, you can use net::ssh 2.x:

http://net-ssh.rubyforge.org/

Some of the functionality you usually utilize in Expect can be invoke in
this module.

There is also a separate wrapper library Net::SSH::Telnet which gives an
API almost identical to Net::Telnet (which in turn is very expect-like)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top