Skip to content

Instantly share code, notes, and snippets.

@mgalardini
Created July 18, 2012 10:55
Show Gist options
  • Save mgalardini/3135541 to your computer and use it in GitHub Desktop.
Save mgalardini/3135541 to your computer and use it in GitHub Desktop.
Sysadmin one-liners
#!/bin/bash
if [ "$#" -lt 1 ]; then
search=$(cat /var/log/apache2/access.log | awk '{print $1"-"$4}')
else
search=$(cat /var/log/apache2/access.log | grep $1 | awk '{print $1"-"$4}')
fi
single=$(for i in $search; do ip=$(echo $i | awk 'BEGIN {FS = "-"}; {print $1}'); datetime=$(echo $i | awk 'BEGIN {FS = "-"}; {print $2}' | sed 's/\[//' | awk 'BEGIN {FS = ":"}; {print $1}'); loc=$(geoiplookup $ip | awk 'BEGIN { FS = ":" }; {print $2}' | sed -e 's/^[ \t]*//' | sed 's/ /_/g'); echo -e $datetime"-"$loc"-"$ip;done)
final=$(for i in $(echo $single | tr ' ' '\n' | sort | uniq); do ip=$(echo $i | awk 'BEGIN {FS = "-"}; {print $3}'); whoz=$(whois $ip | grep NetName | awk 'BEGIN {FS = ":"}; {print $2}' | sed 's/^ *//g' | sed 's/ /_/g' | head -n 1); whoz2=$(whois $ip | grep netname | awk 'BEGIN {FS = ":"}; {print $2}' | sed 's/^ *//g'| sed 's/ /_/g' | head -n 1); whoz3=$(whois $ip | grep OrgName | awk 'BEGIN {FS = ":"}; {print $2}' | sed 's/^ *//g'| sed 's/ /_/g' | head -n 1); whoz4=$(whois $ip | grep descr | awk 'BEGIN {FS = ":"}; {print $2}' | sed 's/^ *//g'| sed 's/ /_/g' | head -n 1); echo -e $i"-"$whoz"-"$whoz2"-"$whoz3"-"$whoz4;done)
echo $final | tr ' ' '\n' | awk 'BEGIN {FS = "-"}; {print "\033[1;31m"$1"\033[1;0m \033[1;32m"$2"\033[1;0m \033[1;34m"$3"\033[1;0m \033[1;33m"$4" "$5"\033[1;0m "$6" "$7}' | sed 's/_/ /g'
#!/bin/bash
if [ "$#" -lt 1 ]; then
cat /var/log/apache2/access.log | awk '{print $11}' | sort | uniq | sed 's/"//g'
else
cat /var/log/apache2/access.log | grep $1 | awk '{print $11}' | sort | uniq | sed 's/"//g'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment