Bash One-Liners: List and sort Asterisk endpoints which have become unreachable.

A nice quick bash one-liner to pluck out any endpoints which have become unreachable from the messages log file, List the amount of times they appear as unreachable and sort by the most problematic first using a combination of Grep, Uniq, Sort and Awk.

$ grep -i "unreachable" /var/log/asterisk/messages | awk '{print $6}' | sort | uniq -c | sort -rn

grep -i “unreachable” /var/log/asterisk/messages Pulls out all the lines of the log which show an endpoint becoming unreachable

awk ‘{print $6}’ Cuts out the only bit we are interested in (The peers name/account)

sort …Well.. Sorts it, So all duplicates are together!

uniq -c Discards any duplicate lines, the -c switch prefixes the lines with each occurance

sort -rn Sorts the final list (Consisting of our unreliable peers and the total amount of times they’ve appeared in the logs.) Then prints them out, Starting with the most problematic first (The one which appears most in the logs). The -r switch reverses the list output (Highest total first) and n forces numerical sorting.