Skip to content

Instantly share code, notes, and snippets.

@sheeplogh
sheeplogh / gist:3421464
Created August 22, 2012 02:06
grep an accesslog(apache) file within a specific time period
$ cat ACCESS_LOG | awk '$4 >= "[29/Jan/2012:12:00:00" && $4 < "[29/Jan/2012:13:00:00"'
@sheeplogh
sheeplogh / gist:3521534
Created August 30, 2012 01:42
[mod_rewrite]Redirect HTTP requests by UA(PC/Smartphone/...)
## SET ENV "UA" ##
### DEFAULT
RewriteRule .* - [E=UA:default]
### PC
RewriteCond %{HTTP_USER_AGENT} Windows [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Mac\sOS\sX [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Macintosh [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Mac_ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Linux [NC,OR]
@sheeplogh
sheeplogh / gist:3550039
Created August 31, 2012 07:56
[shell] List file-permissions in octal notation
$ find ./20120831_testdir -type f -print0 | xargs -0 stat --format='%a %N' | sed -e "s/[\`']//g"
755 ./20120831_testdir/2009032/httpdconf.pl
777 ./20120831_testdir/showmod.sh
@sheeplogh
sheeplogh / amazons3.lf
Created September 3, 2012 02:34
[urchin] logformat conf for Amazon S3
#-----------------------------------------------------------------------------------------------
# Urchin Logformat Map - Custom Format
#
# Urchin uses this file to determine which fields are contained in the log file.
# The file contains name/value pairs which affect the parsing of the data fields.
# The log file can contain lines with up to two different formats which are
# denoted as Primary and Secondary in the name/value pairs below.
#
# Lines beginning with a '#' are ignored. Fields in this file are separated by
# whitespace (spaces or tabs). Any fields that have whitespace in them must be
@sheeplogh
sheeplogh / gist:4372179
Created December 25, 2012 07:59
get total bytes transferred in MB from apache accesslog.
$ cat ACCESS_lOG | awk '{bytes = bytes + $10} END {print bytes/1048576}'
@sheeplogh
sheeplogh / gist:4379059
Last active December 10, 2015 04:08
[shell] Get network throughput (Mbps, Average 10 minutes) on Linux machines from sar.
## Rx
$ LANG=C sudo sar -n DEV | grep eth0 | grep -v Average | awk '{print $1, $5*8/1048576}'
## Tx
$ LANG=C sudo sar -n DEV | grep eth0 | grep -v Average | awk '{print $1, $6*8/1048576}'
# Ex.
$ LANG=C sudo sar -n DEV -f /var/log/sa/sa24 | grep eth0 | grep -v Average | awk '{print $1, $6*8/1048576}'
...
23:20:01 4.32473
@sheeplogh
sheeplogh / akamai_esw3c_2_combined.sh
Created April 9, 2013 10:57
Akamai's standard log format (esw3c (W3c–style) Log Format) to combined(JST)
#!/bin/sh
LANG=C
/bin/gawk -F"\t" '$0 !~ /^#/ {
## make epochtime from timestamp
split($1, d, "-");
split($2, t, ":");
timestamp=d[1]" "d[2]" "d[3]" "t[1]" "t[2]" "t[3];
epochtime=mktime(timestamp);
@sheeplogh
sheeplogh / maintenance.conf
Last active December 16, 2015 02:09
apache conf for display maintenance page with 503. (for VirtualHost context)
ExpiresActive On
ExpiresDefault A0
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
ErrorDocument 503 /maintenance/index.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance/.*$
RewriteRule ^.*$ - [R=503,L]
@sheeplogh
sheeplogh / get_connections_from_accesslog.pl
Created October 16, 2013 08:52
ApacheのCombined + %D 形式のアクセスログから1秒毎の同時接続数を集計するスクリプト。 タイムスタンプを接続が開始された時刻とみなして、%D の間は接続が維持されているものとする。 結果はあくまで参考値。 スクリプトと同じディレクトリに access_log をおいてから実行する。
#!/usr/bin/perl
###
### ApacheのCombined + %D 形式のアクセスログから1秒毎の同時接続数を集計するスクリプト。
### タイムスタンプを接続が開始された時刻とみなして、%D の間は接続が維持されているものとする。
### 結果はあくまで参考値。
### スクリプトと同じディレクトリに access_log をおいてから実行する。
###
use strict;
@sheeplogh
sheeplogh / gist:7701112
Last active December 29, 2015 16:59
count hits of some URLs per day from access_log
#!/bin/sh -e
TODAY=`date +%Y%m%d`
if [ $# -eq 1 ]
then
TARGET_DATE=$1
else
TARGET_DATE=`date -d "1 day ago" +%Y%m%d`