Skip to content

Instantly share code, notes, and snippets.

@prakhar1989
Created October 19, 2014 14:01
Show Gist options
  • Save prakhar1989/0b615134eb9019a4ee48 to your computer and use it in GitHub Desktop.
Save prakhar1989/0b615134eb9019a4ee48 to your computer and use it in GitHub Desktop.
IP Stats
#!/bin/bash
logfile=/var/log/nginx/site-access.log
count=20
if [ "$1" != "" ];
then
echo "Data for file: $logfile with filter: $1"
grep $1 $logfile | awk '{print $1}' | sort | uniq -c | sort -nk1 -r | head -n $count
else
echo "Data for file: $logfile"
awk '{print $1}' $logfile | sort | uniq -c | sort -nk1 -r | head -n $count
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment