I have the following script running in the background:
while true; do
{ file=$(/somescript); echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat $file; } | nc -l -p 20000
done
It works fine, except that /somescript is executed once instantly, before even any request is made to port 20000, and then it waits and responds correctly.
What am I doing wrong? It's supposed to run /somescript only when there's a request 20000