# Net/telnet

**URL:** <https://www.ruby-forum.com/t/net-telnet/64649>\
**Category:** Ruby\
**Created:** [August 15, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/net-telnet/64649 "2006-08-15T14:12:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 15, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/1 "2006-08-15T14:12:26Z")

</div>

Hi all:

I was unable to start “su -” after open telnet conexion. I got:

:-================ Timeout::Error =====================  
C:\ruby\lib\ruby\1.8/net/telnet.rb:551:in `waitfor' raise TimeoutError, "timed out while waiting for more data" C:\ruby\lib\ruby\1.8/net/telnet.rb:680:in`cmd’  
waitfor({“Prompt” =\> match, “Timeout” =\> time\_out})  
C:\Documents and Settings\admin\Escritorio\telne\_test.rb:12  
localhost.cmd(“su -”)  
C:\ruby\lib\ruby\site\_ruby\1.8/rubygems/custom\_require.rb:27:in  
`require’  
gem\_original\_require path

=============================================  
Exception: timed out while waiting for more data

Any idea?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 15, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/2 "2006-08-15T14:12:38Z")

</div>

Hi,

At Thu, 10 Aug 2006 18:35:05 +0900,  
removed\_email\_address@domain.invalid wrote in [ruby-talk:207510]:

> I was unable to start “su -” after open telnet conexion. I got:
> 
> :-================ Timeout::Error =====================  
> C:\ruby\lib\ruby\1.8/net/telnet.rb:551:in `waitfor' raise TimeoutError, "timed out while waiting for more data" C:\ruby\lib\ruby\1.8/net/telnet.rb:680:in`cmd’  
> waitfor({“Prompt” =\> match, “Timeout” =\> time\_out})  
> C:\Documents and Settings\admin\Escritorio\telne\_test.rb:12  
> localhost.cmd(“su -”)

In common, the prompt of superuser differs from ordinary users.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 15, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/3 "2006-08-15T14:12:39Z")

</div>

On Thu, Aug 10, 2006 at 06:35:05PM +0900, removed\_email\_address@domain.invalid  
wrote:

> C:\Documents and Settings\admin\Escritorio\telne\_test.rb:12

Telnet uses a regex to match the shell prompt, so that it knows that the  
preceding command has terminated.  
When you ‘su -’, you change the prompt (probably a $ becomes a #, or  
your login changes), so Telnet never sees the end of the ‘su -’ command.  
You should change the regex used to match the prompt when you create the  
Net::Telnet object, so that it matches both your normal prompt and the  
root prompt, i.e

conn = Net::Telnet.new(‘Host’ =\> ‘bla’, ‘Prompt’ =\>  
/me@host$|root@host#/)

Yoann

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 15, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/4 "2006-08-15T14:13:18Z")

</div>

Yoann G. wrote:

> > C:\ruby\lib\ruby\1.8/net/telnet.rb:680:in `cmd’
> 
> Net::Telnet object, so that it matches both your normal prompt and the  
> root prompt, i.e
> 
> conn = Net::Telnet.new(‘Host’ =\> ‘bla’, ‘Prompt’ =\> /me@host$|root@host#/)
> 
> Yoann

IIRC there’s a “standard” regex one uses that will match most common  
UNIX prompts, but I can’t remember what it is. It includes “$” and “#”  
and “%”, but I don’t remember what else there is.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 15, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/5 "2008-01-15T14:06:23Z")

</div>

Hey,  
The default Prompt value can be the one given below in the new  
method :

```
           "Prompt" => /[$%#>] \z/n

```

Regards,  
Prasad.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 15, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/net-telnet/64649/6 "2006-08-15T14:13:23Z")

</div>

Hi,

At Thu, 10 Aug 2006 22:18:38 +0900,  
M. Edward (Ed) Borasky wrote in [ruby-talk:207547]:

> IIRC there’s a “standard” regex one uses that will match most common  
> UNIX prompts, but I can’t remember what it is. It includes “$” and “#”  
> and “%”, but I don’t remember what else there is.

“#” is for super user. “$” and “%” are for ordinary users, and  
defaults in Bourne shell and C shell respectively.
