I tried to process telnet output in bash and i stumbled upon this syntax to send telnet commands to a server
( echo open $host $port
sleep 1
echo $cmd1
sleep 1
) | telnet
What i would like to know is why the "open" command is required and why
( echo $host $port
...
) | telnet
results in a "?Invalid command" error.
...because a hostname is not a valid command name? There is a big difference between
$ telnet host port
and
$ telnet
telnet> host port
Where the latter is what your echo
command is effectively doing.
The one-liner automatically runs an open
command, so it is basically equivalent to this:
$ telnet
telnet> open host port
But I'm not at all sure why you wouldn't just run telnet host port
in the first place.