-
-
Save mpapis/2851420 to your computer and use it in GitHub Desktop.
Filter requests to Rails application by IP address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/" for 220.181.108.76 at 2012-06-01 06:28:48 +0000 | |
Processing by PostsController#index as HTML | |
Rendered posts/index.html.erb within layouts/application (2.0ms) | |
Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.2ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Filter requests to Rails application by IP address | |
# | |
# Usage: | |
# tail -f log/production.log | log_filter.sh [IP] | |
# | |
# By default tries to obtain current IP address from $SSH_CLIENT or by querying http://ifconfig.me | |
if [[ $# -eq 0 ]]; then | |
if [[ -z $SSH_CLIENT ]]; then | |
ip=$(curl -s http://ifconfig.me) | |
else | |
ip=$(echo $SSH_CLIENT | sed -e "s/ .*//") | |
fi | |
else | |
ip=$1 | |
fi | |
awk -v IP=$ip '$1=="Started" && $5==IP {accept=1; } $1=="Started" && $5!=IP {accept=0; } accept==1 { print; }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment