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?
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?
Yes, you can usee tee for that:
This way output will be printed on both stdout and copied over into /var/log/local.log on the system you are running ssh command from.
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: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.