Created
February 25, 2013 14:47
-
-
Save compor/5030272 to your computer and use it in GitHub Desktop.
sort filezilla server log entries by session id
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 | |
| # | |
| # entry example | |
| # | |
| # (1579051) 10/16/2009 0:02:13 AM - (not logged in) (192.168.1.11)> USER chris | |
| # | |
| # sort -k1n fzs-2009-10-16.log | |
| # does not work properly because when the session id and timestamp are the same | |
| # it goes on and tries to sort based on the message | |
| # if the timestamp granularity was high enough it would work (and so much faster!) | |
| # | |
| [ $# -ne 1 ] && echo "number of args required is 1" && exit 1 | |
| [ ! -e $1 ] && echo "file $1 does not exist" && exit 2 | |
| FILEPATH=`dirname $1` | |
| LOGNAME=`basename $1` | |
| LOGNAME_SORTED=${FILEPATH}/${LOGNAME}".sorted" | |
| SID_SORTED_FILENAME=${FILEPATH}/"fzlog_sid_sorted.$$" | |
| rm -f $LOGNAME_SORTED | |
| awk '{ split( $1, L, "\\(|\\)" ); print L[ 2 ]; }' $1 | sort | uniq > ${SID_SORTED_FILENAME} | |
| cat ${SID_SORTED_FILENAME} | while read line | |
| do | |
| grep "^($line)" $1 >> ${LOGNAME_SORTED} | |
| done | |
| rm -f ${SID_SORTED_FILENAME} | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment