Reputation: 39055
I have a service running on localhost:port. In a bash script I want to connect to this port, send a request, and read back the response - essentially automating a telnet session. What's the best way of doing this? Am looking at /dev/tcp, netcat or telnet/expect.
Thanks
Upvotes: 0
Views: 4155
Reputation: 34592
I believe you can automate this, I recall seeing the telnet commands (using Ctrl+M markers for simulating a carriage return) and putting these commands into a text file and issuing
telnet somehostAnd the output was sent out to the standard output (your terminal) which can then be captured.
Hope this helps, Best regards, Tom.
P.S: Here's a link to something found using this on the command line here.
Upvotes: 0
Reputation: 272217
Expect was built to do this precise task. It will not only handle the client/server dialog, but also the scenarios of timeouts, disconnects etc. It's available in multiple implementations (Perl and Tcl are two off the top of my head) so you can choose one to fit in with your current standards and environment.
Upvotes: 0
Reputation: 5330
Expect is great if you can get it to do what you'd like: it's easy to pickup and work with just by reading the man page.
Upvotes: 0