-
Notifications
You must be signed in to change notification settings - Fork 17
/
nextcloud-usage-report.sh
41 lines (30 loc) · 1.09 KB
/
nextcloud-usage-report.sh
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
#!/bin/bash
# By Georgiy Sitnikov.
#
# This script works with https://apps.nextcloud.com/apps/user_usage_report
#
# Will generate report and output it in cacti format
# Supports Argument as "user" if you need to check statistic for one user only
# run ./nextcloud-usage_report.sh user to get specific user information
# AS-IS without any warranty
#
# output fields are: storage_all, storage_used, shares_new, files_all, files_new, files_read
Command=/var/www/nextcloud/occ
OPTIONS="usage-report:generate"
LOCKFILE=/tmp/nextcloud_usagereport
TMPFILE=/tmp/nextcloud_usagereport_tmp
PHP=/usr/bin/php
CentralConfigFile="/etc/nextcloud-scripts-config.conf"
if [ -f "$CentralConfigFile" ]; then
. $CentralConfigFile
fi
[ -f "$LOCKFILE" ] && exit
touch $LOCKFILE
#get usage information
$PHP $Command $OPTIONS $1 > $LOCKFILE
#generate log in Cacti format
awk -F, '{print $1"storage_all:"$3" " $1"storage_used:"$4" " $1"files_all:"$5" " $1"shares_new:"$6" " $1"files_new:"$7" " $1"files_read:"$8" "}' $LOCKFILE | sed 's/"//g' | sed ':a;N;$!ba;s/\n/ /g' >> $TMPFILE
cat $TMPFILE
rm $TMPFILE
rm $LOCKFILE
exit 0