Advertisement
Hack5190

PiHole Log Filter

Jan 26th, 2022
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #######################
  4. #
  5. # pihole log filter - 26-January-2022 - Hack5190 (at) protonmail (dot) com
  6. #
  7. # usage: tail -f /var/log/pihole.log | ~/monitor/highlight.sh 1.1.1.1 0.0.0.0
  8. #
  9. # 1.1.1.1 is the IP to trap / display - it will be highlighted in Yellow
  10. # 0.0.0.0 will be highlight in Red to show blocked - use 127.0.0.1 to highlight forwarded requests
  11. #
  12. # FYI: the counter displayed between query results is the # of non-matching lines
  13. #
  14. #######################
  15.  
  16. # Text color
  17. red=$(tput bold;tput setaf 1)
  18. yellow=$(tput bold;tput setaf 3)
  19.  
  20. # The loop
  21. reset=$(tput sgr0)
  22. count=0
  23. while read line; do
  24.     if (echo $line | grep $1 > /dev/null) ; then
  25.         printf "\r"
  26.         read line_2
  27.         echo $line | sed -ue "s/\($1\)/$yellow\1$reset/; s/\($2\)/$red\1$reset/"
  28.         echo $line_2 | sed -ue "s/\($1\)/$yellow\1$reset/; s/\($2\)/$red\1$reset/"
  29.     else
  30.         (( count++ ))
  31.         printf "%s\r" "$count"
  32.     fi
  33. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement