DEV Community

Li
Li

Posted on

Sending real-time server logs to remote server with nc

Remote debugging is hard, especially when you can't ssh into remote server, monitor the log generating. Maybe it is the server inside an office, or the security policy of your client doesn't allow remote login. But still, we can use nc to deliver the logs, real-timely. No complex setup required, just a little more than the beloved tail -f command.

nc(netcat) should be available in most the servers, so additional software are not required(and maybe your client doesn't have the permissions to install new software).

Only two steps, first, on your own server, you may setup a server to listen for connections:

nc -lvk <PORT_NUMBER> | tee remote.log
Enter fullscreen mode Exit fullscreen mode

Second, just let your client use the nc to sync the logs to your server, and now you get logs.

tail -f server.log | nc <SERVER_IP> <PORT_NUMBER>
Enter fullscreen mode Exit fullscreen mode

Actually, even there is no nc at your client's server. You may actually send the by the following command

tail -f server.log > /dev/tcp/<SERVER_IP>/<PORT_NUMBER>
Enter fullscreen mode Exit fullscreen mode

And remember to close the nc service when are done.

Top comments (0)