Bash script won't stay open in background after running through while

Posted by jfreak53 on Ask Ubuntu See other posts from Ask Ubuntu or by jfreak53
Published on 2012-12-12T20:49:09Z Indexed on 2012/12/12 23:20 UTC
Read the original article Hit count: 306

Filed under:
|
|

I can't get the following bash script to stay open after the first message is received from NC:

#!/bin/bash
port=3333
nc -l $port | while read msg; do notify-send Alert "$msg"; done

After the first message it exits. I want it to stay open and continue monitoring for new messages from NC.

I know that if I launch nc -l port without the while loop it stays open and I can chat away between the two connections even disconnect from the connected host.

I am sending the message using:

echo 'done' | nc IP port

© Ask Ubuntu or respective owner

Related posts about networking

Related posts about bash