[olug] Bash TCP scripting

Luke -Jr luke at dashjr.org
Sat Dec 29 08:52:48 UTC 2007


On Friday 28 December 2007, Travis Owens wrote:
> Just out of curiosity, has anyone ever done any scripting with bash, using
> /dev/tcp or some form of socket connections? I'm looking at doing something
> bi-directional, receiving the response after the connection is established,
> parsing it, using a piece to send back and parsing the final response.
>
> The information I've found so far on the net, show how to establish a
> connection, but not necessarily what to do with it after it's
> established...

exec 3<>/dev/tcp/irc.freenode.net/6667
echo 'USER foobar or whatever goes here' >&3
IFS= read -u 3 ResponseLine

Do note that BASH does not support any kind of select(), so more than a single 
connection gets tricky without forking.




More information about the OLUG mailing list