On 03/01/2009 04:40 AM, John McKown wrote:
> On Fri, 27 Feb 2009, John Summerfield wrote:
>>> command </dev/tcp/${HOST}/${PORT}
>> 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
> 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?
Exactly:
<quote man="bash">
Opening File Descriptors for Reading and Writing
The redirection operator
[n]<>word
causes the file whose name is the expansion of word to be opened for
both reading and writing on file descriptor n, or on file descriptor 0
if n is not specified. If the file does not exist, it is created.
</quote>
Communication is bidirectional, pipes are not.
Adapted from bftpget [ftp://ftp.heise.de/pub/ct/listings/0702-178.zip]:
# choose an unused file descriptor (most probably greater than 2)
FILEDESCRIPTORNUMBER=5
# establish connection
exec ${FILEDESCRIPTORNUMBER}<>/dev/tcp/${HOST}/${PORT}
# check errorlevel
...
# send command
echo ${COMMAND} >&${FILEDESCRIPTORNUMBER}
# retrieve response
read -u ${FILEDESCRIPTORNUMBER} RESPONSE
# do something
...
# close connection
exec ${FILEDESCRIPTORNUMBER}>&-
Steffen
Linux on System z Development
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Erich Baier
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
----------------------------------------------------------------------
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