Skip to content

Commit

Permalink
Add script to split logs by pid.
Browse files Browse the repository at this point in the history
Thank to Ilpo Jarvinen for the script.
NOTE: Make sure that manual additions to the log files have the correct pid before this script is run.
  • Loading branch information
Gnonthgol committed Jul 17, 2012
1 parent 6832e33 commit 1b6f002
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions split_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /bin/bash

LOG_DIR="logs"
LOG_FILES=`ls -d $LOG_DIR/* | grep -v -e "-"`

for file in $LOG_FILES
do
echo "Splitting file $file"

awk '
{
fname=gensub(".log$","","h",FILENAME);
if (prev != fname) {
header=""; sep=""; inhdr=1;
}
prev=fname;
if (substr($3, 1, 1) == "#") {
inhdr=0;
pid=gensub("[]#]","","g",$3);
if (!(pid in started)) {
print header > fname "-" pid ".log"
started[pid]=1;
}
print $0 > fname "-" pid ".log"
} else {
if (inhdr) {
header=header sep $0;
sep="\n";
} else {
print $0 > fname "-" pid ".log"
}
}}' $file
done

#echo removing old log files
#rm $LOG_FILES

0 comments on commit 1b6f002

Please sign in to comment.