1

I'm trying to run a couple remote commands on a box that will not give me a normal shell (it's a device with a proprietary shell).

I'm also running the command from a device with a limited set of resources so I can't add something like Expect.

I tried the following to no avail:

#!/bin/ksh
( sleep 2
  echo username
  sleep 5
  echo password
  sleep 5
  echo show whoison ) | telnet 192.168.1.10

It successfully enters the username and fails on entering the password. "\n" didn't seem to work either.


I've tried SSH before but the shell that the device is using wouldn't let me pass commands (I tried ssh user@host 'show whoison')

4 Answers 4

1

first. do not. it's not secure.

second - only if you have to...

line below - similar to yours - works for me - but probably it's a race condition and depends on how quickly your device expects credentials.

( echo someLogin;  echo somePass; echo reboot 0;  echo reboot 0 ; sleep 3; ) | telnet 192.168.0.141

you can as well use expect

3
  • I see double spaces but suspect there's something else. Did you have control characters in that command line? Dec 9, 2009 at 19:57
  • @BasicallyMoney.com - no i did not had special chars
    – pQd
    Dec 9, 2009 at 19:58
  • @Jason - nevertheless it is ugly hack and with expect you can make it a bit better.
    – pQd
    Dec 9, 2009 at 20:28
1

For automatic logging in with telnet, you really want to use expect

NOTE: Really and truly, you don't want to use telnet either. There are SSH alternatives available for nearly every platform now, including Cisco routers.

SSH allows you

  1. Passwordless entry via public key authentication
  2. Easier execution of remote commands
  3. Passing of return values via scripts
  4. A secure environment that is encrypted end to end
  5. Agent authentication so that passwords can be used on the keys, but the keys are stored in memory when used once.

If you have the power to use SSH, use it. If not, use expect.

2
  • I tried SSH too but couldn't send the commands effectively into the shell that the device provided.
    – Jason
    Dec 9, 2009 at 19:56
  • 1
    You might want to post another question regarding that issue than, to work at it from both angles. Dec 9, 2009 at 19:59
0

I clicked through to your question to recommend expect, but then saw your limitation. Sorry, but telnet can't be used the way you want. Have you tried netcat or you can't install anything?

Also, telnet is only safe for trusted local-only traffic; otherwise use SSH.

0

Does using the -t option to ssh help at all with the problem of the commands not working when using ssh?

You must log in to answer this question.