#!/usr/local/bin/bash cd ~ export ACCESS_LOGS=access_log.`date +%Y%m`?? cat logs/access_log 2>/dev/null > temp-bandwidthcount cat domains/*/logs/access_log 2>/dev/null >> temp-bandwidthcount cat logs/$ACCESS_LOGS 2>/dev/null >> temp-bandwidthcount cat domains/*/logs/$ACCESS_LOGS 2>/dev/null >> temp-bandwidthcount zcat logs/$ACCESS_LOGS.gz 2>/dev/null >> temp-bandwidthcount zcat domains/*/logs/$ACCESS_LOGS.gz 2>/dev/null >> temp-bandwidthcount echo -n "Bandwidth used for `date +"%B %Y"`: " cat temp-bandwidthcount | awk '{sum += $10} END {print sum/1024/1024,"MiB"}' rm temp-bandwidthcount
1. Upload as showbandwidth
2. chmod u+x it
3. run it (~# ./showbandwidth) to get your current month's (HTTP) bandwidth usage.
Output Sample: Bandwidth used for August 2006: 0.46237 MB
Original credit to Filip: http://textsnippets.com/posts/show/346.
Old version (only use if you have changed where Apache saves its log files):
#!/usr/local/bin/bash cd ~ export ACCESS_LOGS=access_log.`date +%Y%m`?? cat `find . -name 'access_log' 2>/dev/null` 2>/dev/null > temp-bandwidthcount # Today's log cat `find . -name "$ACCESS_LOGS" 2>/dev/null` 2>/dev/null >> temp-bandwidthcount # For any not gzipped zcat `find . -name "$ACCESS_LOGS.gz" 2>/dev/null` 2>/dev/null >> temp-bandwidthcount echo -n "Bandwidth used for `date +"%B %Y"`: " cat temp-bandwidthcount | awk '{sum += $10} END {print sum/1024/1024,"MB"}' rm temp-bandwidthcount
Same directions as original above.