Public
snipts » logs
showing 1-11 of 11 snipts for logs
-
∞ Script that acts as a login shell replacement to log everything an user does
#!/bin/bash # # spy shell by mcree@tricon.hu # # This is a shell wrapper for the script program from bsdutils # that can be used in /etc/passwd as a login shell to log # everything an user does. # # Protected by the General Public License v2 # export SHELL="/bin/bash" script="/usr/bin/script" mydir="/var/log/spyshell" whoami=`/usr/bin/whoami` date=`/bin/date +%s.%N` mytty=`/bin/ps hTotty | head -n1 | tr '/' '_'` myprefix="$mydir/$whoami/$date.$mytty.$$" mkdir -p "$mydir/$whoami" mycompress() { gzip -9 "$myprefix".* 2>/dev/null exit 0 } trap mycompress 0 if [ "$TERM" = "dumb" ]; then #noninteractive #set > $myprefix.dumb.env #echo "$*" > $myprefix.dumb.params #gzip "$myprefix".* ##strace -f -o $myprefix.strace /bin/bash "$@" exec $SHELL "$@" else #interactive if [ -z "$SPYSHELL" ]; then export SPYSHELL=yes set > $myprefix.env echo "$*" > $myprefix.params $script -f -q -t $myprefix.log 2>$myprefix.timing else #set > $myprefix.dumber.env #echo "$*" > $myprefix.dumber.params #gzip "$myprefix".* exec $SHELL "$@" fi fi
-
∞ Apache Log File Retriever via FTP
#!/bin/bash ## GLOBAL CONFIGS ## LOG=$(date +"%Y%m") let DAY=$(date +"%d")-1 SITES=( [0]="domain1.tld" [1]="domain2.tld" [2]="domain3.tld" ) USERS=( [0]="user1" [1]="user2" [2]="user3" ) PASSW=( [0]="passw1" [1]="passw2" [2]="passw3" ) FILES=( [0]="www.$LOG$DAY" [1]="www.$LOG$DAY.gz" [2]="www.$LOG$DAY" ) for index in 0 1 do [ ! -d /srv_admin/remote_logs/${SITES[index]} ] && mkdir -p /srv_admin/remote_logs/${SITES[index]} || : ftp -in ${SITES[index]}<<FTPEOF quote USER ${USERS[index]} quote PASS ${PASSW[index]} cd www_logs lcd /srv_admin/remote_logs/${SITES[index]} binary verbose passive get ${FILES[index]} exit FTPEOF done
-
∞ Bash Log Rotator
#!/bin/bash ## GLOBAL CONFIGURATIONS LOGS=( [0]="/usr/home/morpheus/cron/cron.log" ) DATE=$(date +"%y_%m_%d") for index in 0 do cp ${LOGS[index]} ${LOGS[index]}.${DATE} gzip -m9 ${LOGS[index]}.${DATE} cat /dev/null > ${LOGS[index]} printf "Log file rotated :)\n ============== \n" > ${LOGS[index]} done
-
∞ Log file error histogram analysis
#!/usr/bin/python # Useful spotting patterns in errors logged to files. Intended to be used # on rolled log files where the filename contains the date or some other # unique index or sequence. # # Example: # foo-2009-04-23.log # foo-2009-04-24.log # foo-2009-04-25.log # # Use grep to generate the input for this script. Use a pattern which will # match a variety of possible events. This works best when only one such # event is reported per line. # # Use the '-o' flag to output only the matched section: # # > grep -o "\b\w*Exception\b" * # # foo-2009-04-23.log:RuntimeException # foo-2009-04-23.log:IOException # foo-2009-04-23.log:IOException # foo-2009-04-23.log:IOException # foo-2009-04-24.log:FileNotFoundException # foo-2009-04-24.log:IOException # foo-2009-04-25.log:OutOfMemoryException # # Pipe this output to this script and you will get cross-referenced # histograms of: # # By input file (date): # Count for each error type # # By Error type: # Count for each day of ocurrence # # Number of errors (per file/date) - descending order # # Number of errors (per error type) - descending order import sys from math import log date_exception = dict() exception_date = dict() exception_all = dict() date_all = dict() def splitlines(): input = sys.stdin.readlines() for line in input: (date, exception) = line.strip().split(":") if (not date_all.has_key(date)): date_all[date] = 0 date_all[date] += 1 if (not exception_all.has_key(exception)): exception_all[exception] = 0 exception_all[exception] += 1 if (not date_exception.has_key(date)): date_exception[date] = dict() count_map = date_exception[date] if (not count_map.has_key(exception)): count_map[exception] = 0 count_map[exception] += 1 if (not exception_date.has_key(exception)): exception_date[exception] = dict() count_map = exception_date[exception] if (not count_map.has_key(date)): count_map[date] = 0 count_map[date] += 1 def print_bar(prefix, label, value): print prefix + "%-30s (%5d) %s" % (label, value, "#" * int(log(value+1)*3)) if __name__ == '__main__': splitlines() print "\n" for k in date_exception.keys(): d = date_exception[k] print k l = sorted(d.iteritems(), key=lambda (k,v): (v,k), reverse=True) for item in l: print_bar(" ", item[0], item[1]) print "\n" for k in exception_date.keys(): d = exception_date[k] print k l = sorted(d.iteritems(), key=lambda (k,v): (v,k), reverse=True) for item in l: print_bar(" ", item[0], item[1]) print "\n" for s in sorted(exception_all.iteritems(), key=lambda (k,v): (v,k), reverse=True): print_bar("", s[0], s[1]) print "\n" for s in sorted(date_all.iteritems(), key=lambda (k,v): (v,k), reverse=True): print_bar("", s[0], s[1])
-
∞ path, dv2
Logs -/home/httpd/vhosts/mt-example.com/statistics/logs
-
∞ commandline search server logs for activity in time frame
# following date/time is day/month/year:hour:min:sec # as in 02/Feb/2009:23:59:59 # leave off more for a broader range like: # 02/Feb/2009:0 ...here's mine: [your structure may vary] grep -rn "26/Sep/2008:01:" /usr/local/apache/domlogs/*
-
∞ Watch Apache Error Log
tail -f /usr/local/apache/logs/error_log
-
∞ View MySQL Log
less /var/log/mysqld.log
-
∞ For a typical qmail installation with Plesk, you can monitor the logs with the following command:
tail -f /usr/local/psa/var/log/maillog
-
∞ Clearing log files (without deleting them)
find /var/log/ -name '*.*' -not \( -type d \) -print0 | xargs -0i sh -c "cat /dev/null > "{}""
-
∞ watch the last 50 lines of a file
tail -f --lines=50 system.log



Practical Web 2.0 Applications with PHP