#!/bin/sh # This script (easylogtool.cgi) is for; # - downloading any log (past & current) # - checking first or last 50 entries of these logs # - Copying a log to your own directory # - Showing the list of all logs. # - Showing first or last 2 lines of all logs # # NOTE: Powweb has improved its OPS and you can brows/download # all log files via OPS -> Packages -> site tools # https://ops.powweb.com/?module=packages&submodule=sitemanager&page=%3Fmodule%3Dlogs # # # Installing: # # Copy & Paste this script into a new file named "easylogtool.cgi" # in a password protected directory and invoke it. # http://yourdomain.com/protected/easylogtool.cgi # # This script needs NO EDITING what so ever. # # DISCLAIMER : # This script is offered for fellow PowWeb users, free of charge, # and with no warranty of any kind. # Place it in a protected directory to keep it from missuse by others. # Avoid downloading huge logs via this script. # Rather, click 'Copy' and then use FTP to download. # LOG='/log' L=`id -u` L=$(($L -500)) UDN=${L%${L#?}} UD="$UDN/$L" ARG=$1 case "$ARG" in [ae]*) ####### Download command ####### # By default it will let you download uncompressed log file. # Change the command if you want to download zip compressed log file. # CMD='d' ;# Uncompressed log download # CMD='dz' ;# Zip compressed log download # CMD='d' ;; i_*) F=${ARG#i_} FR=${F%.txt} FR=${FR%_*}.${FR##*_} if [ ! -f "$FR" ] ; then case "$FR" in domain.cgi) echo -e "Content-type: text/html
Showing the detailed lists of all logs\n"
ls -l $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
echo "Showing the first 2 lines of all logs\n"
head -2 $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
echo "Showing the last 2 lines of all logs\n"
tail -2 $LOG/*/$UD* 2>LL.err;cat LL.err;rm LL.err
echo "Diagnostic mode\n"
exec 2>&1
#ls -al /log;
ls -al $LOG/access/;echo
hostname;HOST=`host $HTTP_HOST`;echo $HOST;
HIP=`expr "$HOST" : "[^0-9]*\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)"`
echo
set -x
dig $HTTP_HOST
whois ${HTTP_HOST#www.}
host $HIP
uptime
ps -uxww
set +x
echo '
'
ls -al $LOG/access/${UD}_access_log
for i in 0 1 2 3 4 5 6 7 8 ; do
ls -al $LOG/access.$i/${UD}_access_log
done
ls -al $LOG/error/${UD}_error_log
for i in 0 1 2 3 4 5 6 7 8 ; do
ls -al $LOG/error.$i/${UD}_error_log
done
echo "Copying"
LOGDIR=${DOCUMENT_ROOT%/htdocs}/logs
if [ ! -d $LOGDIR ] ; then mkdir $LOGDIR 2>&1; fi
cp -v $LOG/$AE$NUM/${UD}_${AE}_log $LOGDIR/`date '+%Y-%m-%d'`_${AE}_log${NUM} 2>&1
echo "Showing first 50 lines
Path to log: $LOG/$AE$NUM/${UD}_${AE}_log
"
head -50 $LOG/$AE$NUM/${UD}_${AE}_log 2>LL.err;cat LL.err;rm LL.err
echo "Showing last 50 lines
Path to log: $LOG/$AE$NUM/${UD}_${AE}_log
"
tail -50 $LOG/$AE$NUM/${UD}_${AE}_log 2>LL.err;cat LL.err;rm LL.err
echo "