views:

706

answers:

5

Hi,

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

+1  A: 

...........Use Curl.

jldupont
+1  A: 

netcat should pretty much be able to do what you want.

Joey
A: 

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.

antik
A: 

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.

Brian Agnew
As far as I can tell with expect though, is that it actually expects a particular response, e.g "Password". In this case, I don't know what I'll be getting back - I just want to read whatever comes back.
Richard
I think you should be able to wildcard this
Brian Agnew
A: 

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 somehost

And 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.

tommieb75
tommieb75