shosei

awk connecttime

Feb 23rd, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.72 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # connecttime - Reports cumulative connection time for month/year
  4. # entries found in the system log file.
  5. # For simplicity, this is an awk program.
  6.  
  7.  
  8. log="/var/log/system.log" #this is just /var/log/system on some machines
  9. tempfile="/tmp/$0.$$"
  10.  
  11. trap "rm $tempfile" 0
  12.  
  13. cat <<'EOF'> $tempfile
  14. BEGIN{
  15.     lastmonth=""; sum = 0
  16. }
  17. {
  18.  if {$1 != lastmonth && lastmonth !=""){
  19.    if (sum > 60){ total = sum/60" hours"}
  20.     else    { total = sum " minutes" }
  21.     print lastmont ": "total
  22.     sum=0
  23.  }
  24.   lastmonth=$1
  25.   sum +=$8
  26.  }
  27.  END{
  28.    if(sum>60){total = sum/60 " hours"}
  29.    else { total = sum " minutes"}
  30.    print lastmonth ":" total
  31.   }
  32.   EOF
  33.  
  34.  grep "Connect time" $log | awk -f $tempfile
  35.  
  36. exit 0
Advertisement
Add Comment
Please, Sign In to add comment