APACHE-LOGS-utility - Apache search logs tool for cPanel

From wiki.morphey.org

Jump to: navigation, search

This script, allows you to look for in the logses of Apache of cPanel a lace without overloading the system.


apache_logs_search.sh

 
#!/bin/bash
 
# !--------------------------------------------------!
#       Search in apache logs for cPanel - Tool
#
#               coded by morphey
#
#                               (morphey@morphey.org)
# !--------------------------------------------------!
 
 
# Settings
DIR_LOG_APACHE="/usr/local/apache/domlogs"
FILE_RESULT="risultati.txt"
 
####################
# DO NOT CHANGE HERE
####################
 
if [ -z "$1" ]
then
        echo "Usage: `basename $0` [string_to_search]"
        exit 65
fi
 
STR_SEARCH="$1"
 
echo "# !--------------------------------------------------!"
echo "#       Search in apache logs for cPanel - Tool"
echo "#"
echo "#               coded by morphey"
echo "#"
echo "#                               (morphey@morphey.org)"
echo "# !--------------------------------------------------!"
echo
echo "System->Search on dir[ "$DIR_LOG_APACHE" ] the string[ "$STR_SEARCH" ] and the result is storage in file[ "$FILE_RESULT" ].."
echo
cd $DIR_LOG_APACHE
 
rm -f $FILE_RESULT
for i in `dir|grep -v "bytes_log" | grep -v "smtpbytes_log" | grep -v "imapbytes_log.offse" | grep -v "popbytes_log.offset" | grep -v "ftp." | grep -v ".sh"`
do
        out=`php -r 'if (is_dir($argv[1])){echo "1";}else{echo "0";}' -- $i`
        if echo "$out" | grep -q "1"
        then
                echo "Dir-> "$i
                for z in `dir $i|grep -v "bytes_log" | grep -v "smtpbytes_log" | grep -v "imapbytes_log.offse" | grep -v "popbytes_log.offset" | grep -v "ftp."`
                do
                        echo "Search ["$STR_SEARCH"] in file-> $i/$z"
                        if grep -q $STR_SEARCH $i/$z
                        then
                                echo "$i/$z" >> $FILE_RESULT
                                echo "------->>>> Checked-2!!!"
                                grep -Ri "$STR_SEARCH" $i/$z >> $FILE_RESULT
                        fi
                done
        else
                echo "Search ["$STR_SEARCH"] in file-> "$i
                if grep -q $STR_SEARCH $i
                then
                        echo "$i" >> $FILE_RESULT
                        echo "------->>>> Checked!!!"
                        grep -Ri "$STR_SEARCH" $i >> $FILE_RESULT
 
                fi
 
        fi
done
 
 

Usage with:

 
chmod +x apache_logs_search.sh
./apache_logs_search.sh word_to_search
 
Personal tools