Weil das Skript beendet wird und damit den Befehl mit beendet.
Nein, Script läuft weiter, bis ich es manuell beende. Trotzdem beendet sich nc sofort.
Ich behaupte mal, dass das hier Deine Lösung ist: nohup
nohup ist mir bekannt, hilft in diesem Fall nicht weiter.
Im Terminal ausgeführt funktioniert das aber.
Solange Du das Terminal nicht schließt. Richtig?
Ja, wenn ich das Terminal schließe, beendet nc, so wie es auch sein soll.
Das Problem läßt sich auch ohne Script nachstellen. Öffne 2 Terminals
Fall 1:
# Terminal 1:
~$ bash -c "nc 192.168.2.1 3333 > /tmp/ncid.tmp &"
~$
# Terminal 2:
~$ ps -C nc
PID TTY TIME CMD
~$
nc läuft nicht
Fall 2:
# Terminal 1:
~$ bash -c "nc 192.168.2.1 3333 | tee /tmp/ncid.tmp > /dev/null &"
~$
# Terminal 2:
~$ ps -C nc
PID TTY TIME CMD
10641 pts/2 00:00:00 nc
~$
nc läuft
das gleiche Spiel ohne "bash -c"
Fall 1:
# Terminal 1:
~$ nc 192.168.2.1 3333 > /tmp/ncid.tmp &
[1] 10659
~$
# Terminal 2:
~$ ps -C nc
PID TTY TIME CMD
10659 pts/2 00:00:00 nc
~$
Fall 2:
# Terminal 1:
~$ nc 192.168.2.1 3333 | tee /tmp/ncid.tmp > /dev/null &
[1] 10823
~$
# Terminal 2:
~$ ps -C nc
PID TTY TIME CMD
10822 pts/2 00:00:00 nc
~$
Hier läuft nc in beiden Fällen
Zum testen, ob nc richtig funktioniert, kann man eine Nachricht abschicken, oder sich selbst anrufen
~$ echo "MSG: Eine Nachricht" | nc 192.168.2.1 3333
200 NCID Server: ARC_ncidd 0.01
< ... >
CIDLOG: *DATE*02032013*TIME*0558*LINE*49xxx*NMBR*+49xxx*MESG*NONE*NAME*NO NAME*
MSG: Eine Nachricht
~$
Die Nachricht findet sich dann auch in /tmp/ncid.tmp