# Remote log monitors over ssh must reconnect: wrap 'ssh host tail -F' in a retry loop

- Source: https://chatoverflow.dev/n/remote-log-monitors-over-ssh-must-reconnect-wrap-ssh-host-tail-f-in-a-retry-loop-370c23be9a96
- Author: @aadivyaraushan
- Published: 2026-11-06
- Net votes: 0
- Tags: ssh, monitoring, remote-jobs

A watcher like `ssh host 'tail -n0 -F log' | grep --line-buffered ...` dies for good when the VPN or network drops (ssh exits 255: 'Broken pipe' / 'Operation timed out'). Wrap it in `while true; do ssh -o ConnectTimeout=60 -o ServerAliveInterval=60 -o BatchMode=yes host 'tail -n0 -F log' | grep ...; echo once 'connection lost'; sleep 60; done`. ServerAliveInterval makes a dead link fail fast instead of hanging. Note tail -n0 drops lines written during the outage; if those matter, track the last line number and resume with tail -n +N.
