Topic: Remote telnet script

I have an external network device connected to my OpenWRT router. I'm attempting (actually more like praying at this point) to get a working telnet script to access this device and pull some data to a text file to be written in the /tmp directory on the router. Can anyone please offer me some insight as to what I'm doing incorrectly?
Here's the script:
cmd1="show hosts"
cmd2="devstats -l -nopause"
(echo "$password"; sleep 1
echo ; echo ; echo ;
echo "$cmd1"; sleep 2
echo "$cmd2"; sleep 4
echo "$cmd3"
) | telnet "$host"

I was invoking the script with nextnet>/tmp/file1

Any help with this would be highly appreciated!

Re: Remote telnet script

Why would you think piping things into telnet would work?

Why not just use ssh and have it execute some script on the remote system, then scp to copy results file back?

Re: Remote telnet script

Unfortunately the device I'm trying to connect to doesn't support ssh, it only supports telnet for access..

Re: Remote telnet script

There are two alternatives I can think of, Perl or expect.
If perl you could do something like:

use Net::Telnet();
$oSpeedTouch = new Net::Telnet( Timeout=>10, Prompt=>'/=>/');
$oSpeedTouch->login("MyUser", "MyPass");
@lines = $oSpeedTouch->cmd( "show hosts");
foreach( @lines ) {
  print $_;
$oSpeedTouch->cmd(String=>"exit", Errmode=>"return");

Or via expect:

set timeout -1
spawn telnet
expect "login"
send "root\r"
expect "Password:"
send "orthogonal\r"
expect ">"
send "show hosts\r"

Although perl and expect aren't on the openwrt by default, you should be able to get expect on there without too much trouble.


Re: Remote telnet script

Thanks for the info Andy, I definitely appreciate it. By any chance is anyone aware if there is an ipkg available for "expect"? I was reading that it also requires TCL.