Skip to content

Instantly share code, notes, and snippets.

@szajbus
Created June 1, 2012 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save szajbus/2851271 to your computer and use it in GitHub Desktop.
Save szajbus/2851271 to your computer and use it in GitHub Desktop.
Filter requests to Rails (2.3.x) application by IP address
#!/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
@mpapis
Copy link

mpapis commented Jun 1, 2012

try this, should be a lot faster https://gist.github.com/2851420

@szajbus
Copy link
Author

szajbus commented Jun 1, 2012

@mpapis That would show only single lines, but the goal is to show requests in full (logged in multiple lines)

@mpapis
Copy link

mpapis commented Jun 1, 2012

updated with awk and example of my log file, seams like we have different formats

@szajbus
Copy link
Author

szajbus commented Jun 5, 2012

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