Skip to content

Instantly share code, notes, and snippets.

@benburkert
Created November 8, 2011 02:04
Show Gist options
  • Save benburkert/1346803 to your computer and use it in GitHub Desktop.
Save benburkert/1346803 to your computer and use it in GitHub Desktop.
a single shot web server
#!/bin/bash
if [[ -z $1 ]] ; then
echo "File argument missing" 1>&2
exit 1
else
file="$1"
fi
if [[ -z $2 ]] ; then
echo "Serving on port 8080"
port="8080"
else
port="$2"
fi
{ echo -ne "http/1.0 200 ok\r\ncontent-length: $(wc -c <$file)\r\nContent-Type: plain/text\r\n\r\n"; cat $file; } | netcat -l -p $port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment