If you want to quickly save a file through http but you don’t want to install a web server, you can just use netcat.
You can run:
[code language=”bash”]
while true; do { echo -e ‘HTTP/1.1 200 OK\r\n’; cat index.html; } | nc -l 8080; done
[/code]
index.html can be any file you want to serve it.
You can access it after that as: http://host_ip:8080/
For that purpose I’m using:
rm -f out ; mkfifo out ; while true ; do cat out | nc -l localhost 8080 | tr -ud ‘\r’ | awk ‘/^GET /{system(“cat “$2″>out”)}’ ; done
netcat forever! http://www.catonmat.net/blog/unix-utilities-netcat/
Nice. Using netcat would be called cheating though, no?
Doesn’t require root to run!
This one is longer. http://en.wikipedia.org/wiki/Netcat#Setting_up_a_one-shot_webserver_on_port_8080_to_present_the_content_of_a_file –
it also provides the Content-Length to clients.
Cheers!
It’s not cheating. He’s using an unreserved-port.
Or you can use Python: python -m SimpleHTTPServer
Or you can use Twisted: twistd -n web –path .
There is a good chance that you have Twisted already installed as a dependency of something else. Otherwise the Python module will serve you well (the Twisted version can serve multiple requests concurrently).
You don’t need root for port 8080; only if you want port < 1024.
You could also do php -s http://localhost:8080/ without root?
http://php.net/manual/en/features.commandline.webserver.php
If your netcat is new enough, you can also use:
h(){ nc -lp8080 -c’r=HTTP/1.0;f=`head -n1|cut -d\ -f2`;[ -f .$f ]&&echo “$r 200\nContent-Type: `file -bi .$f`\n”&&cat .$f||echo $r 404′;h;}
which fits in a tweet 🙂
php -S
Will also do the trick, if you’ve got a recent php version installed. It will of course serve php-files, which can be both good and bad. 😛
A simple web server via one line of bash that can fit in a tweet you say? Nice. http://t.co/N5xHk02jVT
Cool! RT @cballou: A simple web server via one line of bash that can fit in a tweet you say? Nice. http://t.co/DdhJIaTWX1
Web server in one line of bash http://t.co/TQ8FYkuJ1o (http://t.co/s5XUpE8ewa)
Web server in one line of bash http://t.co/cVXQuCLrGy
http://t.co/JzIss9NGiG
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Web server in one line of bash (http://t.co/pLculpdb32) http://t.co/rGTxGDKr1q
Web Server in One line of Bash – http://t.co/LqwWW0eJ7x
Web server in one line of bash http://t.co/hM0z0xW2uH
http://t.co/92p3oDlv6n
Покруче #nginx будет.
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
いいね / “Web server in one line of bash | Răzvan Tudorică” http://t.co/vZZgP7IFYZ
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Webserver mit nur einer Zeile Shell-Script:
http://t.co/dU2LKh4irA http://t.co/SvvyEc7ern
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Web server in one line of bash http://t.co/7psNreDJ71 See also comments for more ideas
noch ein Beispiel für schlichte Eleganz auf der Kommandezeile – der Einzeiler Webserver #linux #bash http://t.co/HiFh83rTZ3
Web server in one line of bash | Răzvan Tudorică http://t.co/17hZNozSZo
Web server in one line of bash http://t.co/T2JtkBvT3Z
Web server in one line of bash | Răzvan Tudorică http://t.co/YZsNhKkZok
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
Web server in one line of bash | Răzvan Tudorică http://t.co/4QFG7XIcQv
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Web server in one line of bash http://t.co/l0UgZ6vHUx
Web server in one line of bash using netcat http://t.co/kBuXvAIf9B
I prefer “python -m SimpleHTTPServer [port]” 😛 RT @hnycombinator: Web server in one line of bash http://t.co/1Wp546Ua7d
Web server in one line of bash | Răzvan Tudorică http://t.co/PF9D9gZFhg
A web server in one line of bash http://t.co/z19Pi1m80d
Run a webserver in a single line of bash. http://t.co/OXIiYlLFxw #bash #scripting #web
Web server in one line of #bash – http://t.co/aYnKHBBWWs
RT @AngeZanetti: Web server in one line of bash | Răzvan Tudorică http://t.co/4QFG7XIcQv
RT @newsycombinator: Web server in one line of bash http://t.co/GbSC1aWzCX
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
RT @AngeZanetti: Web server in one line of bash | Răzvan Tudorică http://t.co/4QFG7XIcQv
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
Web server in one line of bash http://t.co/ooympQJjra
Web server in one line of bash http://t.co/Jl6pfMq8JJ
Way fun, Turns out it can server an image too. Replace index.html with file.jpg (png gif) and you get the image displayed as well. Obvious, but neat to see the image. Great on razvan. I’ve used inet to do this with cat, first time in bash. cool.
[gn]Web server in one line of bash :If you want to quickly save a file through http but you dont want to install a.. http://t.co/ENeQegH6IS
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
Not that stability or compliance is a huge issue for this use case, but there should be another \r\n seperating the response headers/status line from the body.
Web server in one line of bash http://t.co/WgQbA7fqs8
Instead of http://t.co/qDncui0f7c I would do: pil @lib/http.l –server 8080 index.html
One-liner webserver: while true; do { echo -e ‘HTTP/1.1 200 OK\r\n’; cat index.html; } | nc -l 8080; done http://t.co/hYLAIRpEso
Web server in one line of bash
http://t.co/QyBZfuozfu
Tek satırlık bir konsol komutu ile web sunucu http://t.co/nn952umpFC
Web server in one line of bash http://t.co/EpVjGFbzXs #linux #sysadmin
Web server in one line of bash | Răzvan Tudorică http://t.co/yK3GqggFNC
Web server in one line of bash | Răzvan Tudorică http://t.co/MvLq2rjqQP
RT @konradfoerstner: web server shell one-liner: $ while true; do { echo -e ‘HTTP/1.1 200 OK\r\n’; cat index.html; } | nc -l 8080; done htt…
Cool: Web server in one line of bash http://t.co/hL6la9V4Xa
Web server in one line of bash http://t.co/HEy4E2Xs70 #fb
Web server in one line of bash http://t.co/WrfoSXx1yD
Einen Webserver in 1 Zeile erstellen?
So gehts http://t.co/cLflM267E2
Je nach Einsatz nichtmal verkehrt.
Es braucht nur netcat.
RT @AngeZanetti: Web server in one line of bash | Răzvan Tudorică http://t.co/4QFG7XIcQv
RT @newsyc150: Web server in one line of bash http://t.co/TQ8FYkuJ1o (http://t.co/s5XUpE8ewa)
Web server in one line of bash | Răzvan Tudorică http://t.co/lmo1ccYgzl 1行でhttpサーバだと。
Very Cool! Web server in one line of bash with #Netcat. If you want to quickly access a file through #http.
http://t.co/VXYyWnzC8W
RT @hnycombinator: Web server in one line of bash http://t.co/jFpbq5wLmb
Excellent idea: one-line web server in #bash http://t.co/QTy2v0RtJ3
RT @lxndrp: Excellent idea: one-line web server in #bash http://t.co/QTy2v0RtJ3
RT @lxndrp: Excellent idea: one-line web server in #bash http://t.co/QTy2v0RtJ3
RT @lxndrp: Excellent idea: one-line web server in #bash http://t.co/QTy2v0RtJ3
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @lxndrp: Excellent idea: one-line web server in #bash http://t.co/QTy2v0RtJ3
RT @JamiesonBecker: Totally awesome.
A web server in ONE LINE of bash:
http://t.co/9CM8Fgu7Ij
RT @konradfoerstner: web server shell one-liner: $ while true; do { echo -e ‘HTTP/1.1 200 OK\r\n’; cat index.html; } | nc -l 8080; done htt…
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
“@crazybob: Web server in one line of Bash: http://t.co/In5BySPSTH” – yes, if you ignore that it’s using netcat.
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
RT @crazybob: Web server in one line of Bash: http://t.co/tqTi8a6Ycu
Web server in one line of bash
http://t.co/RzrTRrLAbW
while true; do { echo -e ‘HTTP/1.1 200 OK\r\n’; cat index.html; } | nc -l 8080; done
Webserver via bash = AWESOME!
http://t.co/0FREwtaDuG
Web server in one line of bash http://t.co/l0gD71ljXZ
“@crazybob: Web server in one line of Bash: http://t.co/C4KxtcClnv” – nice, short and easy.
RT @Linuzifer: Webserver in einer Zeile, bash. Alles andere ist Overhead. http://t.co/Qb8fIkhPqo
Uau RT @mavcunha @crazybob Web server in one line of Bash: http://t.co/J3z3EKdLfP
nc has “-k, –keep-open” option, to use instead of “while true”. This line below working with any web browser! Thank You. 🙂
nc -kl 5432 -c ‘echo -e “HTTP/1.1 200 OK\r\n$(date)\r\n\r\n”;echo “How are you today?”‘