[lug] Telnet with here document

Stephen Queen svq at peakpeak.com
Wed Apr 6 06:55:11 MDT 2005


I've been trying to write a script that accesses a wireless
access point/modem. The interface uses telnet. I thought a
simple here document should do the trick. The form of the
here document I've tried is

***********************************************
#!/bin/bash

telnet <<ENDofDATA
open XXX.XXX.XXX.XXX
username
password
command
command
...
bye
ENDofDATA

*************************************************

I've tried several variations of this, but telnet opens the
connection, then appears to break the connection before it
queries for the username. If I use the  form

open XXX.XXX.XXX.XXX -l username

it doesn't appear to query for a password before it breaks
the connection. If I enter the commands from the command
line, it works fine. If I replace the command telnet with
cat, it performs as expected. I tried to google on telnet
and here documents, and found an article that said it was
possible, and showed how to do it with ftp, but had no
telnet examples.

Has anyone here had any success with this?

Stephen Queen




More information about the LUG mailing list