Scenario: I have load balanced servers running a web application. To debug I'd like to see the output of the same log file (such as the nginx log) combined into a single stream, e.g. a tail -f
on all servers in the same cluster, where one of them is the server I am currently logged in.
Here is a simple approach using background processes, for example with three servers app-server-01, app-server-02, app-server-03, where I am logged in to the first one:
ssh -t "jneutron@app-server-02" "tail -f /var/log/nginx/access.log" &
ssh -t "jneutron@app-server-03" "tail -f /var/log/nginx/access.log" &
tail -f /var/log/nginx/access.log
This combines the log output across multiple servers as desired, but you end up with lingering background processes after hitting Ctrl-C.
I was looking for an automated way to clean up those background processes, and came up with a script, shared here as an answer.