Realtime logfile/traffic analyses (apache webserver)

Live „top 10“ useragents
~$: cat access.log | awk -F '"' '{print $6}' | sort | uniq -c | sort -nr | head

„Top 10“ useragents certain date and hour (grep pattern may differ)
~$: grep '12/Sep/2011:15' access.log | awk -F '"' '{print $6}' | sort | uniq -c | sort -nr | head

„Top 20“ referrers from the last 5000 hits
~$: tail -5000 access.log | awk '{print $11}' | tr -d '"' | sort | uniq -c | sort -rn | head -20
~$: tail -5000 access.log | awk '{freq[$11]++} END {for (x in freq) {print freq[x], x}}' | tr -d '"' | sort -rn | head -20

Top 20 IPs from the last 5000 hits
~$: tail -5000 access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
~$: tail -5000 access.log | awk '{freq[$1]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20

Top 20 URLs from the last 5000 hits
~$: tail -5000 ./access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -20
~$: tail -5000 ./access.log | awk '{freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20

Top 20 URLs requested from a certain ip from the last 5000 hits
~$: IP=1.2.3.4; tail -5000 ./access.log| grep $IP | awk '{print $7}' | sort | uniq -c | sort -rn | head -20
~$: IP=1.2.3.4; tail -5000 ./access.log | awk -v ip=$IP ' $1 ~ ip {freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20

real time analysis with apachetop
HowTo: monitor your website in real time with apachetop
/usr/sbin/apachetop -f /path/to/your/log/access.log

Linux Verzeichnis- und Dateirechte korrigieren/setzen

Um die Zugriffsrechte aller (Unter)Verzeichnissen und/oder (Plaintext)Dateien  innerhalb eines Verzeichnisses gleich zu setzten (in diesem Beispiel 755 für Verzeichnisse, 644 für Dateien) kann die Liste der Verzeichnisse/ Dateien per find ermittelt werden, jede/s gefundene Verzeichnis / Datei wird an chmod übergeben:

~$: find ./* -type d -exec chmod 755 {} \;
~$: find ./* -type f -exec chmod 644 {} \;

PHP Locale/Zeitzone setzen

Folgende Codes wurde unter PHP 5.2.x getestet.

Setzen der Standard Zeitzone:
date_default_timezone_set('Europe/Berlin');

Ausgeben aller installierten Locales:
ob_start();
system('locale -a');
$str = ob_get_contents();
ob_end_clean();
var_dump(split("\\n", trim($str)));

Setzen einer Locale:
setlocale(LC_ALL, 'de_DE.ISO8859-15', 'de_DE.ISO8859-1', 'de_DE');
setlocale(LC_ALL, 'de_DE.UTF-8');

Ob nun UTF-8 oder UTF8 gesetzt werden muss, scheint abhängig vom eingesetzten Server zu sein.
In meinem Test musste UTF-8 gesetzt werden. Weitere Infos unter: http://de.php.net/de/setlocale