[lug] Telnet with here document
Stephen Queen
svq at peakpeak.com
Wed Apr 6 13:35:47 MDT 2005
> No way :-) Telnet doesn't read from standard in, it always tries
> to read from the controlling terminal. This is a known nuissance,
> fortunately eased by the existence of handy script libraries (for
> Perl that would be Net::Telnet).
> Of course, any serious old-time unixer will now suggest 'expect' [1]
> writtn exactly do do what you want.
Once you said this I knew you were right, but I did find a
page that claimed you could do it.
http://www.die.net/doc/linux/abs-guide/here-docs.html
>
> #--------x snip x-----------------------------------------------
> #!/usr/bin/expect
>
> spawn telnet your.host.here
> sleep 5
>
> # wait for the ogin prompt
> expect login
>
> #send username
> send username\r
>
> #wait for password prompt
> expect passw
> send password\r
>
> send command\r
>
> #--------x snip x-----------------------------------------------
>
> [1] man 'expect' will give a good intro and there should be a rather
> good set of examples in the documentation folder of your distro.
>
Using what you gave me here, I was able to hack together a
dirty little script that did the job I wanted.
I was reluctent to jump into expect for 2 reasons:
1. I was just feeling too lazy to try and figure out another
scripting language.
2. The target machine was an embbed PC104 that I would have
to install expect on.
Thanks for making it easier!
Stephen Queen
More information about the LUG
mailing list