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