0

So we have Embedded Linux board running Linux.
We can connect to that board using telnet and that spawns shell and gives access to it.

Now I am writing a bash script where I want to run commands on that shell and get its output.

e.g. My commands are something like below command over telnet and see if that was successful or not.

test -c /dev/null

When I run it like below I always get 1 as exit status

{ test -c /dev/null; sleep 1;} | telnet <board ip addr>

If possible I don't want to use expect,

Any suggestion/pointers ?

ART
  • 1,509
  • 3
  • 29
  • 47

1 Answers1

1

With SSH could trivially and robustly have done:

ssh yourhost 'test -c /dev/null'

With a simple shell on a TCP port, you could somewhat robustly but annoyingly have used:

echo 'test -c /dev/null; echo $?' | nc -q 1 yourhost 1234

telnet is instead notoriously timing sensitive and tricky to script, so since you don't want to do it robustly with expect, you can try to kludge it:

{ sleep 1; echo 'test -c /dev/null; echo $?'; sleep 1; } | telnet somehost
that other guy
  • 116,971
  • 11
  • 170
  • 194