Pete's Linux Advent Calendar 2008

The 7th day

Networking with Bash

With bash you can do networking, if your version is compiled with support for it. Unfortunately Debian's version has this feature disabled, so you may have to re-compile the package and modify the debian/rules file to --enable-net-redirections. But here's how you can use it:
#!/bin/bash
exec 3<> /dev/tcp/localhost/80
cat <<EOT >&3
GET / HTTP/1.1
Host: localhost
Connection: close

EOT
while read line <&3; do
    echo "$line"
done
exec 3<&-
exec 3>&-

Pete's Linux Advent Calendar 2008

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram