Created
June 1, 2012 11:10
-
-
Save szajbus/2851271 to your computer and use it in GitHub Desktop.
Filter requests to Rails (2.3.x) application by IP address
This file contains hidden or 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 | |
output=false | |
while read line; do | |
if [[ $line =~ ^Processing ]]; then | |
if [[ $line =~ $ip ]]; then | |
output=true | |
else | |
output=false | |
fi | |
fi | |
$output && echo $line | |
done |
you're right, this works for Rails 2.3.x log format
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated with
awk
and example of my log file, seams like we have different formats