Question

I am using netcat in a bash script as a pseudo server in order to run additional bash scripts from inputs entered. It's been something of an enjoyable side project, however I seem to have gotten stuck.

Essentially, The script and code runs perfectly, but output is not displayed until after the server finishes the process; as this can be a 40 hour process, it's not desirable to have the client with a loading screen and no prompt for the entire time.

Simply put, I would like to load a page based off the content to a point, ignoring the output of everything that follows. The code I have thus far is as follows:

#!/bin/bash
while [ $? -eq 0 ]; do
  nc -vlp 8080 -c'(
  r=read
  $r a b c
  z=$r
  while [ ${#z} -gt 2]; do
    $r z
  done
  f=`echo $b|sed "s/[^a-z0-9_.-]//gi"`
  o="HTTP/1.0 200 OK\r\n"
  c="Content"
  if [ -z "$f" ]; then
    f="index.html"
    echo "$o$c-Type: `file -ib $f`\n$c-Length: `stat  -c%s $f`"
    echo
    cat $f
  elif [ "$f"==Encrypt ]; then
    echo $o
    echo
    echo $(bash ~/webSupport.sh currentEncrypt "$b")
    bash ~/webSupport.sh pullVars "$b" &
  else
    echo -e "HTTP/1.0 404 Not Found\n\n404\n"
  fi
  )'
done

I've searched around, and cannot find any way to bypass it, any help would be appreciated.

Was it helpful?

Solution

It should probably be enough to redirect the output streams (to /dev/null or a file if you need to keep it)

bash ~/webSupport.sh pullVars "$b" >/dev/null 2>&1 &

or close them:

bash ~/webSupport.sh pullVars "$b" >&- 2>&- &
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top