Re: Simple expect question

Glynn Clements <[email protected]>
Newsgroups gmane.linux.admin
Message-ID <[email protected]>
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 <[email protected]>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.