0

I am listening on a port for logs coming from a device, then I used netcat to redirect those logs to a text file whenever a log is available on the device and all this to happen in the background using this command (everything works perfect):

nohup nc -kulp <PORT> > <TEXT FILE> &

Now, I am trying to write down a script that will re-run the process above every time listening or forwarding is paused or stopped due to device upgrade or reboot that interupts the process.

My question is how to check if netcat is still listening and forwarding logs coming from port. I cannot use any program other than netcat for this purpose.

1 Answer 1

0

Just try to open a new netcat process on the same port as you did for the first time

nohup nc -kulp <PORT> > <TEXT FILE> &

if it was failed to open, it means your previous netcat is still running or otherwise it will just open a connection if it was not.

Do the same on the sending part as you did on the receiving part above.

Note: You used single redirection > above as it will then overwrite the receiving file whenever you try to reopen the connection, stop better to use double redirection >> for appending mode.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .