I have an application which accepts commands over telnet and performs action and then return the result.
We wrote this following line in a script to automate the action:
{ echo -e '\02~NH02'; sleep 5; } | telnet $ipaddr $port
This command works most of the time, but sometimes it fails, I mean the receiver doesn't receive the command will not perform the action..
So, the idea is to read the return value sent after the command is executed.. If the receiver receives the command it sends "OK
", If no command is received, then no response.
Is there any way to read the response in a shell script..
Thanks for your time
Add this to the end to check for the word ok.
| grep ok
This logs the result to the file logfile and checks it for exactly ok.
{ echo -e '\02~NH02'; sleep 5; } | telnet $ipaddr $port | (set -o pipefail && tee -a logfile | grep ok ;)