To tail a file over ssh, I can use
ssh -t remotebox "tail -f /var/log/remote.log"
However, it is possible to sync the tail with a local file? So a file automatically mirror the update of the tail command?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
Just redirect the stdout.
ssh -t remotebox tail -f /var/log/remote.log > local.log
To append to local.log:
ssh -t remotebox tail -f /var/log/remote.log >> local.log
This will write to the local server.
The remote server would only be written to if you include the redirect in the quotes:
ssh -t removebox "tail -f /var/log/remote.log >> remote.log"
Just suggest another useful way is using logtail. Install
logtail package to the remote host, then run this to get only new lines that have not been read last time:
ssh remotebox logtail -f /var/log/remote.log >> local.log
You can run above command whenever you want to "sync" log, or you can add it to crontab, so it could run automatically. This way is especially userful when you dont have a stable connection, so you can not keep the ssh connection day by day.
Hope this help.