Caddy.log and User-Agents

What is the ssh command to filter User-Agents from caddy.log file and sort them by decreasing number of appearance?

Uhh, I’m not sure the ssh command can do that?

I’ve never done this with a command. You’d probably need a few tools, since you need to do some searching, then some comparisons, counting, and sorting. Might get pretty complicated. Like, the kind of arcane spell a greybeard would come up with. Unless there’s a tool out there somewhere specifically for this.

You might be better off just using goaccess or a similar tool.

True, ssh can’t do it (not sure why it would either), but jq can do it.

1 Like

I don’t know in pure jq but this typical linux piping should put you on track

jq '.["request"]["headers"]["User-Agent"][]' gratiere.log | \
awk '
{
    agent[$0]++
}
END{
    for (i in agent) printf "%d %s\n", agent[i], i
}' | \
sort -k1nr
2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.