Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Last active August 17, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/8535c049e6c732252d2ebf4a8de45b30 to your computer and use it in GitHub Desktop.
Save wpsmith/8535c049e6c732252d2ebf4a8de45b30 to your computer and use it in GitHub Desktop.
Bash/Shell: I need to remember these
# Search the gzipped file for 499s and all 5XXs.
zcat domain.com-YYYY-MM-DD.gz |
grep -P "\"\s((499)|(5\d+))\s"
# Search for all 499s.
zcat domain.com-YYYY-MM-DD.gz | grep "\" 499 "
# Search for all 503s.
zcat domain.com-YYYY-MM-DD.gz | grep "\" 500 "
# Search for all 503s.
zcat domain.com-YYYY-MM-DD.gz | grep "\" 503 "
# Search for all 5XXs.
zcat domain.com-YYYY-MM-DD.gz |
grep -P "\"\s5\d+\s"
# Search for status codes == 499-599.
# zcaterr DOMAIN DATE
# zcaterr domain.com 08-11
function zcaterr() {
zcat $1-2020-$2.gz | grep -P "\"\s((499)|(5\d+))\s"
}
# Search for status codes == 499-599 and return count.
# zcaterrc DOMAIN DATE
# zcaterrc domain.com 08-11
function zcaterrc() {
zcat $1-2020-$2.gz | grep -Pc "\"\s((499)|(5\d+))\s"
}
# Search for any status codes != 2xx, 3xx, 400-489 and return count for a specific string.
# zcaterrstrc DOMAIN DATE "SPECIFIC_STRING"
# zcaterrstrc domain.com 08-11 "wp-cron"
function zcaterrstrc() {
zcat $1-2020-$2.gz | grep -P "\"\s((499)|(5\d+))\s" | grep -c "$3"
}
# Search for any status codes != 2xx, 3xx, 400-489 and return count for a specific string.
# zcaterrstr DOMAIN DATE "SPECIFIC_STRING"
# zcaterrstr domain.com 08-11 "wp-cron"
function zcaterrstr() {
zcat $1-2020-$2.gz | grep -P "\"\s((499)|(5\d+))\s" | grep "$3"
}
# Search some gzipped file for text NC and get whatever word follows and put in results.txt
zcat file.gz |
grep -oP "NC\K\w+" | sort | uniq -c
# Search some gzipped file for text not including certain status codes (200, 3xx, 40x) and certain paths (/wp-login.php)
zcat file.gz |
grep -vP "\"\s20\d+ " | # Ignore 20x
grep -vP "\"\s30\d+ " | # Ignore 30x
grep -vP "\"\s40\d+ " # Ignore 40x
# Search some gzipped file for text and count uniques and display number of times each unique occurs
zcat file.gz |
grep -oP "NC:\K\w+" |
sort | uniq -c | sort -nr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment