Created
October 4, 2013 22:30
-
-
Save alperkokmen/6833924 to your computer and use it in GitHub Desktop.
simple log grepper that executes grep command on one or more hosts over ssh.
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/sh | |
## | |
# Set the variables below and then execute as follows: | |
# | |
# e.g. Search log files for [email protected] string. | |
# $ search-logs "[email protected]" | |
# | |
# e.g. Search log files for [email protected] and display surrounding 3 lines in addition to the matched line. | |
# $ search-logs "[email protected]" "-A 3 -B 3" | |
## | |
# Uncomment and enter host names separated with spaces. | |
# e.g. foo bar baz | |
#HOSTS= | |
# Uncomment and enter the login name you would use to login to the hosts via ssh. | |
# e.g. deployer | |
#SSH_LOGIN_NAME= | |
# Uncomment and enter the path to log files in each host. | |
# e.g. /var/rails/foo/production/current/log | |
#LOG_PATH= | |
GREP_PATTERN=$1 | |
GREP_OPTIONS=$2 | |
for host in $HOSTS ; do | |
ssh $SSH_LOGIN_NAME@$host "grep $GREP_PATTERN $LOG_PATH/*.log --color=always $GREP_OPTIONS" | while read line; do echo "[$host] $line"; done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment