grep logs over SSH on many hosts
ssh host grep pattern file is the oldest log search there is, and it still works. These are the variations that save time when you search more than one server.
Search a remote file
ssh api-01 'grep -n "timeout" /var/log/app/app.log'
Quote the whole remote command so the pattern and wildcards are expanded on the server, not on your laptop.
Include rotated and compressed logs
Logrotate leaves app.log.1, app.log.2.gz and so on. zgrep reads plain and gzipped files alike:
ssh api-01 'zgrep -n "timeout" /var/log/app/app.log*'
Show context around each match
A stack trace is useless without the lines that follow it:
ssh api-01 'grep -n -B 2 -A 20 "NullPointerException" /var/log/app/app.log'
-B adds lines before the match, -A lines after.
Only files from the incident window
On a busy server, old rotated files make the search slow. Limit it to files changed recently:
ssh api-01 'find /var/log/app -name "*.log*" -mmin -120 -exec zgrep -Hn "timeout" {} +'
-mmin -120 keeps files modified in the last two hours. -H prints the file name with each match.
Use ripgrep when it is installed
rg is much faster than grep on large directories and can search compressed files with -z:
ssh api-01 'rg -n -z "timeout" /var/log/app/'
Label output by host and run in parallel
for host in $(cat hosts.txt); do
ssh -o ConnectTimeout=5 "$host" 'zgrep -Hn "timeout" /var/log/app/app.log*' \
| sed "s/^/$host: /" &
done
wait
ConnectTimeout stops one dead host from blocking the rest.
Where the shell stops being enough
These commands are fine for one person and a few servers. During a real incident the team usually needs more: matches from all hosts sorted by time, filtering by level or thread without re-running the search, and a list of servers and paths that everyone shares.
That is the gap Logswarm fills. It runs the same kind of search (ripgrep, zgrep or grep, chosen per location) on each host over SSH, streams matches into one table in the browser, and parses each line into columns with your regex. Log files never leave the servers. See Search the logs for how it works.