John McKown wrote:
On Fri, 27 Feb 2009, John Summerfield wrote:
will establish a TCP connection to ${PORT} on ${HOST}. Replace
/dev/tcp/... with /dev/udp/... and it will do udp instead of tcp. This
redirects stdout. Of course, using < instead of > will redirect stdin and
do a read. So, if you like "netcat" to send some data ala
command | nc ${HOST} ${PORT}
you can use the above > redirection instead and
command </dev/tcp/${HOST}/${PORT}
instead of
nc -l ${HOST} ${PORT} | command
NBD - but it saves forking a process.
but how does one carry on a sensible conversation? I can send stuff to
sendmail, but how do I get its responses?
You can't. It is like netcat - communications is unidirectional. I guess
With netcat I can do this:
20:48 [sum...@mail ~]$ echo -ne 'GET / HTTP/1.1\nhost: www.ibm.com\n\n'
| nc -w 20 ibm.com 80
HTTP/1.1 301 Moved Permanently
Date: Tue, 03 Mar 2009 11:48:24 GMT
Server: IBM_HTTP_Server
Location: http://www.ibm.com/link/redirect.www.ibm.com/www.ibm.com/
Content-Length: 265
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a
href="http://www.ibm.com/link/redirect.www.ibm.com/www.ibm.com/">here</a>.</p>
</body></html>
20:48 [sum...@mail ~]$
As you can see, while netcat doesn't do anything with the data, _I_ get
to see it.
if the far end sends something back over the socket, it is quietly
dropped. Netcat has the same problem. It either sends or receives, but not
both. What you'd like would be more like a bidirectional pipe, if there
were such a thing. IIRC, "pipes" in UNIX are unidirectional. So
bidirectional communications requires two pipes. Something like that might
be possible using this, but I can't really think of how. That might be a
nice enhancement both for IP communications and "piped" communications.
Perhaps a <> symbol?
cmd1 <> cmd2
could possible "cross connect" stdout of cmd1 to stdin of cmd2 as well as
stdin of cmd1 to stdout of cmd2, allowing bidirectional communications.
Use of different fd number could be possible with:
cmd1 n<>m cmd2
where n and m are numbers so that /dev/fd/n of cmd1 talks to /dev/fd/m of
cmd2 and /dev/fd/m of cmd1 to /dev/fd/n of cmd2.
The above would be complicated if somebody naively did:
cmd1 | cmd2 <> cmd3 | cmd4
In any case, unidirectionality does decrease its utility somewhat. But I
doubt that any of us would say that piping output from one command to
another is useless because the second command cannot send anything back to
the first command. How do you get responses back from sendmail if you pipe
to it?
Using netcat, same as above. In fact, I think I have a script someplace
that uses netcat to see whether the Australian Stock Exchange is trading.
I also sometimes use netcat to test whether I can send mail to some
particular server.
--
Q: What do theoretical physicists drink beer from?
A: Ein Stein.
Maranatha!
John McKown
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
Cheers
John
-- spambait
[email protected] [email protected]
-- Advice
http://webfoot.com/advice/email.top.php
http://www.catb.org/~esr/faqs/smart-questions.html
http://support.microsoft.com/kb/555375
You cannot reply off-list:-)
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390