jacknad
jacknad

Reputation: 13739

How to automate BusyBox telnet

I need an automated telnet script between two embedded Linux targets using BusyBox v1.22.1 on the client and BusyBox v1.10.3 on the host. Note: Expect is not available on this system. I've tried the recommendations here without success. For example, this

host=1.1.1.2
port=23 # note - port is not required
pass=xxxx # note - pass is not required 
cmd1=24

( echo open ${host} ${port}
  sleep 1
  echo -e "\r"
  sleep 1
  echo ${pass}
  sleep 1
  echo -e "\r"
  sleep 1
  echo ${cmd1}
  sleep 1
  echo -e "\r"
  sleep 1
  echo exit ) | telnet

returns this

Usage: telnet [-a] [-l USER] HOST [PORT]
Connect to telnet server
        -a      Automatic login with $USER variable
        -l USER Automatic login as USER

So I tried various combinations of 'Usage' (above) without success (it always asks for a manually entered 'login').

Is telnet automatic login broken on BusyBox v1.22.1 or am I just missing something simple?

Upvotes: 0

Views: 6027

Answers (1)

jacknad
jacknad

Reputation: 13739

Eventually got it to work using the original example I pointed to. The confusing part was that the telnet session was exiting without the exit command at the final ")". Also, none of the commands during the telnet session block so the sleep for each command has to be long enough. In this case the 'user' is root and there is no password. I may need to insert a few echo -e "\r" but here is the working command that will be incorporated into the script:

( echo -e "\r"
  sleep 1
  echo root
  sleep 2
  echo ${cmd1}
  sleep 65
  echo ${cmd2}
  sleep 2
  echo ${cmd3}
  sleep 52 ) | telnet $host

Upvotes: 1

Related Questions