Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # connecttime - Reports cumulative connection time for month/year
- # entries found in the system log file.
- # For simplicity, this is an awk program.
- log="/var/log/system.log" #this is just /var/log/system on some machines
- tempfile="/tmp/$0.$$"
- trap "rm $tempfile" 0
- cat <<'EOF'> $tempfile
- BEGIN{
- lastmonth=""; sum = 0
- }
- {
- if {$1 != lastmonth && lastmonth !=""){
- if (sum > 60){ total = sum/60" hours"}
- else { total = sum " minutes" }
- print lastmont ": "total
- sum=0
- }
- lastmonth=$1
- sum +=$8
- }
- END{
- if(sum>60){total = sum/60 " hours"}
- else { total = sum " minutes"}
- print lastmonth ":" total
- }
- EOF
- grep "Connect time" $log | awk -f $tempfile
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment