Reputation: 4547
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
Upvotes: 0
Views: 3865
Reputation: 315
Try using nc, it gives you simple and better way inside script.
#echo -e "\n" | nc 54.160.138.189 80
#echo $? #### IF the output is 0 then connection is success , else it's failed to connect.
Upvotes: 1
Reputation: 161
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 ;)
Upvotes: 0