Skip to content

Instantly share code, notes, and snippets.

View dmgig's full-sized avatar
🔥

Dave M. Giglio dmgig

🔥
View GitHub Profile
@dmgig
dmgig / color_awk
Last active August 29, 2015 14:13
awk: colorize output
tail -n 5000 -f /var/log/requests.log | awk '
/FAIL$/ {print "\033[30m" $0 "\033[0m"} # black
/(\/delete.php)/ {print "\033[31m" $0 "\033[0m"} # red
/(\/move.php)/ {print "\033[32m" $0 "\033[0m"} # green
/(\/request.php)/ {print "\033[33m" $0 "\033[0m"} # yellow
/(\/change.php)/ {print "\033[34m" $0 "\033[0m"} # blue
/(\/part.php)/ {print "\033[35m" $0 "\033[0m"} # magenta
/(\/process.php)/ {print "\033[36m" $0 "\033[0m"} # cyan
/NO AFFECTED ROWS$/ {print "\033[37m" $0 "\033[0m"}' # white
@dmgig
dmgig / unique_column_values
Last active August 29, 2015 14:13
awk: show unique column values
cat /var/log/requests.log | awk ' { print $4 } ' | sort | uniq
@dmgig
dmgig / count_matching_rows
Created January 14, 2015 14:47
awk: count matching rows in log file
awk '/Sep 07/ {total += 1} END {print "total requests = " total}' /var/log/requests.log
@dmgig
dmgig / log_monitor.sh
Created January 14, 2015 14:35
Log monitor. Sums requests by hour. Auto-refresh view each second.
#!/bin/bash
# Log monitor. Sums requests by hour. Auto-refresh view each second.
while :
do
TODAY=$(date +"%b %d")
awk -F: -v t="$TODAY" '$0~t {h[$1]++;m[$1":"$2]++;}END{for(x in h)print x,h[x];'} /var/log/requests.log | sort > /tmp/requests_view.tmp
clear
echo "Requests Pace for"