Basically it takes a sar file, sa17, and gets information on the network section and formats the time which is in 10 minute intervals. The time is set to exactly 10 minutes because this section is part of a larger script which gets other information from sar and the mysql database and concatenates it all together by the time.
Any guidance would be greatly appreciated.
sar -n DEV -f sa17|awk -v mydate="2008-02-17" '
BEGIN {lastdate=99}
{
process=0
if ( substr($3,1,3) == "eth" ) process=1
if ( substr($3,1,3) == "bon" ) process=1
if ( $3 == "eth0" ) process=1
if ( ! ( $2 == "AM" || $2 == "PM" ) ) process=0
if ( $3 == "IFACE" ) process=0
if ( process == 0 ) next
currentdate=$1
if ( lastdate != currentdate && lastdate != 99 )
{
print datehradj":"datemmadj":"datessadj" "myeth0" "myeth1 >> "sarnetwork"
mybond0=0
myeth0=0
}
if ( $3 == "eth0" ) myeth0=$6
if ( $3 == "eth0" ) myeth1=$7
filetime=$1
filehour=substr(filetime,1,2)
fileminute=substr(filetime,4,2)
filesecond=substr(filetime,7,2)
if ( $2 == "AM" && filehour == 12 ) filehour="00"
if ( $2 == "PM" && filehour < 12 ) filehour=filehour+12
filedaysecs=((filehour*60*60)+(fileminute*60))
dateadj=(int(( filedaysecs + 300 ) / 600) * 600)
datehradj=int(((int(( filedaysecs + 300 ) / 600) * 600)) / 3600 )
datemmadj=int((((int(( filedaysecs + 300 ) / 600) * 600)) % 3600 ) / 60 )
if ( datehradj == 0 ) datehradj="00"
if ( length(datehradj) == 1 ) datehradj="0"datehradj
if ( datemmadj == 0 ) datemmadj="00"
datessadj="00"
lastdate=$1
}
END {
print datehradj":"datemmadj":"datessadj" "myeth0" "myeth1 >> "sarnetwork"
}'
In reply to Convert from awk to perl by darthtux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |