#!/bin/sh
# Strace Log Bash Parser by hip0 from pC-fREAK Org. -=== www.pc-freak.org ===-
# A Little Crappy output but 
# much better output compared to strace's :-]
# This Software comes with absolutely NO WARRANTIES.!
# Use at your own.
# Under GPL License V2 and above see the license copying for details.

# log and temp files
file='admin.log';
file1='/tmp/temp';
file2='/tmp/temp1';
a=0;
b=1;

# trap quit
trap if_int INT;

if_int () {
# bye bye galaxy :]
rm -f $file1
rm -f $file2
exit 0;
}

# parsing stuff
parser () {
cat $file | awk '{ print $2 }' | grep -v SIGCHLD | grep -v LARGEFILE | grep -v unfinished | grep -v 0x | sed -e 's/"//g' -e 's/,//g' -e 's/\\177//g' -e 's/\=//g' -e 's/\\10//g' -e 's/\\7//g' -e 's/[A]//g' -e 's/\[//g' -e 's/\\33//g' -e 's/B//g' > $file1
cat /dev/null > file;
count=$(wc -l $file1 | awk '{ print $1 }');
for i in `seq 1 $count`; do
a=$(($a + $b));
name=`cat $file1 | head -n $a | tail -n 1 | head -n 1`;
array[$i]="$name";
if [ "${array[$i]}" == "" ]; then
#echo "empty space";
echo -n -e " " >> $file2;
echo -n -e " ";
elif [ "${array[$i]}" == "\\r" ]; then
#echo "Newline";
echo -e "\r" >> $file2;
echo -e "\r";
elif [ "${array[$i]}" == "\\t" ]; then
echo -e -n "\t" >> $file2;
echo -e -n " [tab..]";
elif [ "${array[$i]}" == "\\n" ]; then
echo -e "\n" >> $file2
echo -e "\n";
elif [ "${array[$i]}" == "SIGINT" ]; then
echo " ^C"; 
echo " ^C" >> $file2;
else
echo -n "${array[$i]}" >> $file2;
echo -n "${array[$i]}";
fi
done
#cat /dev/null > $file
cat /dev/null > $file1
cat /dev/null > $file2
}

# main function
main () {
parser;

}
main;
