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
ncoutputs something when it starts? should I just supress errors etc.? – user224371 Apr 15 '17 at 10:53ncdoes (mine doesn't output anything, and also doesn't have a-pflag). In any case, your script needs to wait until it sees the standard HTTPGETrequest. – Kusalananda Apr 15 '17 at 11:10