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.