# Ruby Expect

**URL:** <https://www.ruby-forum.com/t/ruby-expect/191284>\
**Category:** Ruby\
**Created:** [July 8, 2010, 8:23pm UTC](https://www.ruby-forum.com/t/ruby-expect/191284 "2010-07-08T20:23:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [July 8, 2010, 8:23pm UTC](https://www.ruby-forum.com/t/ruby-expect/191284/1 "2010-07-08T20:23:21Z")

</div>

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 “\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.

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [July 8, 2010, 8:33pm UTC](https://www.ruby-forum.com/t/ruby-expect/191284/2 "2010-07-08T20:33:08Z")

</div>

Hi Richard! Nice to see you!

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

[http://net-ssh.rubyforge.org/](http://net-ssh.rubyforge.org/)

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

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [July 8, 2010, 9:28pm UTC](https://www.ruby-forum.com/t/ruby-expect/191284/3 "2010-07-08T21:28:30Z")

</div>

Rilindo F. wrote:

> Hi Richard! Nice to see you!
> 
> For just logging in, you can use net::ssh 2.x:
> 
> [http://net-ssh.rubyforge.org/](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)
