#! /bin/sh
#
# Input:
# Thu Mar 23 18:05:05 SGT 2006
# Filesystem 1K-blocks Used Available Use% Mounted on
# /dev/sda2 8064304 6240288 1414360 82% /
# /dev/sda1 101089 14928 80942 16% /boot
# none 1030804 0 1030804 0% /dev/shm
# /dev/sdd1 1200501556 541543720 597975824 48% /san
#
# Output:
# 2006-03-23 18:06:05 /boot 16 / 82 /dev/shm 0 /san 48
#
if [ $# -ne 1 ]; then
echo "Usage: $0 "
exit 1
fi
logfile=$1
awk '
function printSample()
{
printf("%s ",timestamp)
for(mp in mount) {
printf("%s %d ",mp,mount[mp])
}
printf("\n")
}
# setup mapping
BEGIN {
month2num["Jan"]="01"
month2num["Feb"]="02"
month2num["Mar"]="03"
month2num["Apr"]="04"
month2num["May"]="05"
month2num["Jun"]="06"
month2num["Jul"]="07"
month2num["Aug"]="08"
month2num["Sep"]="09"
month2num["Oct"]="10"
month2num["Nov"]="11"
month2num["Dec"]="12"
}
# timestamp (good enough pattern matching)
/ [1-9][0-9][0-9][0-9]$/ && length($0)==28 {
if ( timestamp != "" ) {
printSample()
}
split($0,date)
y=date[6]
m=month2num[date[2]]
d=date[3]
hms=date[4]
timestamp=sprintf("%s-%s-%s %s",y,m,d,hms)
}
# mount point and percentage of used
$NF ~ /^\// {
mountpoint=$NF
last2=NF-1
used=substr($last2,1,length($last2)-1)
mount[mountpoint]=used
}
# print last sample
END {
printSample()
}
' $logfile
0 Comments:
Post a Comment
<< Home