Summary: How to run an interactive task in the background?
Details: I am trying to run this simple script under a box (Busybox) as a background task.
myscript.sh &
However, the script stops immediately ...
[1] + Stopped (tty input) myscript.sh
The contents of myscript.sh ... (only part of the relvant, except that I hook on SIGINT, SIGHUP, etc.)
#!/bin/sh catpid=0 START_COPY() { cat /dev/charfile > /path/outfile & catpid = $! } STOP_COPY() { kill catpid } netcat SOME_IP PORT | while read EVENT do case $EVENT in start) START_COPY;; stop) STOP_COPY;; esac done
From simple command line tests, I found that cat and netcat are trying to read from tty. Note that this version of netcat does not have -e to suppress tty.
Now what can be done to avoid myscript stopping?
Things I tried so without success:
1) netcat / cat ... </ dev / tty (or tty output)
2) Running a block containing cat and netcat in a subshell using (). It might work, but then how to capture the cat's PID?
For you, experts ...
The problem still exists. A simple test for all of you:
1) In one terminal run netcat -l -p 11111 (without &)
2) In another terminal, run netcat localhost 11111 and (This should stop after a while with the message Stopped (TTY input))
How to avoid this?
Lovelyvirus
source share