-
Notifications
You must be signed in to change notification settings - Fork 25
/
xferlog-stats-count
executable file
·79 lines (63 loc) · 1.52 KB
/
xferlog-stats-count
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -euf -o pipefail
help()
{
cat <<EOF
$0 options
Count the FTP transfer log items by date, with options for filtering.
Options:
-h Help
-r Remote host to match
-f File path to match
-u User name to match
-c Completion status to match, either "c" or "i"
Example to count transfers of the file name `hello.txt`:
cat /var/log/proftpd/xferlog |
xferlog-count -f hello.txt
Example to count transfers by a user name `alice`:
cat /var/log/proftpd/xferlog |
xferlog-count -u alice
Example to count transfers with a completion status of `c` meaning complete:
cat /var/log/proftpd/xferlog |
xferlog-count -c c
This script expects typical xferlog line format:
* start with a three-field current time, e.g. "Sat Dec 31".
* contain the remote host, file path, and user name.
* end with "c" for complete or "i" for incomplete.
Version: 1.0.0
Contact: Joel Parker Henderson ([email protected])
License: GPL
EOF
}
REMOTE='.*'
FILE='.*'
USER='.*'
COMPLETION='.'
while getopts “r:f:u:c:” OPTION
do
case $OPTION in
r)
REMOTE=$OPTARG
;;
f)
FILE=$OPTARG
;;
u)
USER=$OPTARG
;;
c)
COMPLETION=$OPTARG
;;
h)
usage
exit
;;
?)
usage
exit
;;
esac
done
grep "$REMOTE .*$FILE.* $USER .* $COMPLETION$" |
awk '{print $1,$2,$3}' |
uniq -c