From: Rich Masci on
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.
--
Posted via http://www.ruby-forum.com/.

From: Rilindo Foster on
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.


On Jul 8, 2010, at 2:23 PM, Rich Masci wrote:

> 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.
> --
> Posted via http://www.ruby-forum.com/.
>


From: Brian Candler on
Rilindo Foster wrote:
> 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)
--
Posted via http://www.ruby-forum.com/.