linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Simple expect question
@ 2006-11-13 14:22 urgrue
  2006-11-13 15:05 ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: urgrue @ 2006-11-13 14:22 UTC (permalink / raw)
  To: linux-admin

I'm trying to make a simple script that will do with telnet what one can
do with ssh when you do "ssh hostname command". iow:
telnet somehost command

then it should, using expect (presumably), telnet into somehost, prompt
me interactively for the username/password, and after successfully
logging in run the command specified on somehost.

As simple as that sounds, I can't figure it out. I've gotten this far
which is probably done all wrong:

#!/usr/bin/expect

spawn telnet [lrange $argv 0 0\n]  #telnet to host given on command line
expect { "login:"
	#how to prompt user interactively for input here?
        "password:"
	#how to prompt user interactively for input here?
	#somehow check for successful login here
        send "[lrange $argv 1 99]" #send command-line args to host
        send "exit\r"
}



any help appreciated.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Simple expect question
  2006-11-13 14:22 Simple expect question urgrue
@ 2006-11-13 15:05 ` Glynn Clements
  2006-11-13 19:28   ` Freddie
  0 siblings, 1 reply; 4+ messages in thread
From: Glynn Clements @ 2006-11-13 15:05 UTC (permalink / raw)
  To: urgrue; +Cc: linux-admin


urgrue wrote:

> I'm trying to make a simple script that will do with telnet what one can
> do with ssh when you do "ssh hostname command". iow:
> telnet somehost command
> 
> then it should, using expect (presumably), telnet into somehost, prompt
> me interactively for the username/password, and after successfully
> logging in run the command specified on somehost.

The Wikipedia page for Expect uses this task as its first example:

	http://en.wikipedia.org/wiki/Expect

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Simple expect question
  2006-11-13 15:05 ` Glynn Clements
@ 2006-11-13 19:28   ` Freddie
  2006-11-14 11:09     ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Freddie @ 2006-11-13 19:28 UTC (permalink / raw)
  To: linux-admin


On Nov 13, 2006, at 17:05, Glynn Clements wrote:

>
> urgrue wrote:
>
>> I'm trying to make a simple script that will do with telnet what  
>> one can
>> do with ssh when you do "ssh hostname command". iow:
>> telnet somehost command
>>
>> then it should, using expect (presumably), telnet into somehost,  
>> prompt
>> me interactively for the username/password, and after successfully
>> logging in run the command specified on somehost.
>
> The Wikipedia page for Expect uses this task as its first example:
>
> 	http://en.wikipedia.org/wiki/Expect

Thanks, I had already seen that. The problem with the example is it  
expects the username and password as variables that I'd have to give  
on the command line which I'd rather not do.
Although, maybe I can be a bit kludgey and have a bash script prompt  
for those and then feed them to expect, which seems a bit messy but I  
suppose it'll work.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Simple expect question
  2006-11-13 19:28   ` Freddie
@ 2006-11-14 11:09     ` Glynn Clements
  0 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2006-11-14 11:09 UTC (permalink / raw)
  To: Freddie; +Cc: linux-admin


Freddie wrote:

> >> I'm trying to make a simple script that will do with telnet what  
> >> one can
> >> do with ssh when you do "ssh hostname command". iow:
> >> telnet somehost command
> >>
> >> then it should, using expect (presumably), telnet into somehost,  
> >> prompt
> >> me interactively for the username/password, and after successfully
> >> logging in run the command specified on somehost.
> >
> > The Wikipedia page for Expect uses this task as its first example:
> >
> > 	http://en.wikipedia.org/wiki/Expect
> 
> Thanks, I had already seen that. The problem with the example is it  
> expects the username and password as variables that I'd have to give  
> on the command line which I'd rather not do.

If you're asking about the prompting, my first attempt would be:

	puts -nonewline stderr "Username: "
	flush stderr
	set username [gets stdin]

	puts -nonewline stderr "Password: "
	flush stderr
	exec stty -echo
	set password [gets stdin]
	exec stty echo
	puts stderr ""

This is just normal Tcl, nothing specific to Expect.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-11-14 11:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-13 14:22 Simple expect question urgrue
2006-11-13 15:05 ` Glynn Clements
2006-11-13 19:28   ` Freddie
2006-11-14 11:09     ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).