ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSAdmin/accounting.sh
Revision: 803
Committed: 2006-06-23T04:39:43-07:00 (19 years ago) by douglas
Content type: text/x-sh
File size: 764 byte(s)
Log Message:
Accounting!

File Contents

# User Rev Content
1 douglas 803 #!/usr/bin/env bash
2     # Douglas Thrift
3     #
4     # CCS Computer Science
5     #
6     # Login Accounting
7    
8     wtmp='/var/log/wtmp.0'
9    
10     if [[ -f "$wtmp" ]]; then
11     cat="`which cat`"
12     elif [[ -f "$wtmp.gz" ]]; then
13     cat="`which zcat`"
14     wtmp="$wtmp.gz"
15     elif [[ -f "$wtmp.bz2" ]]; then
16     cat="`which bzcat`"
17     wtmp="$wtmp.bz2"
18     else
19     echo "$wtmp doesn't exist"
20     exit 2
21     fi
22    
23     echo -e '\nDoing login accounting:'
24    
25     declare -a name value
26     declare -i count=0
27    
28     for item in $("`which ac`" -pf <("$cat" "$wtmp") | "`which sort`" -nr -k 2); do
29     if [[ $((count % 2)) -eq 0 ]]; then
30     name[${#name[*]}]="$item"
31     else
32     value[${#value[*]}]="$item"
33     fi
34     count="$count + 1"
35     done
36    
37     count="$count / 2"
38    
39     for (( index = 0; index != count; ++index )); do
40     printf '\t%-16s %8.2f\n' "${name[$index]}" "${value[$index]}"
41     done

Properties

Name Value
svn:executable *