egscripts/egdu/egdu

51 lines
No EOL
1.3 KiB
Bash
Executable file

#!/bin/bash
#
# create static XML page listing disk usage statistics for a directory
#
DIR="/etc/egdu"
NAME="egdu"
CMD="$DIR/egdu"
CONFS=`find $DIR/conf/ -name "*.conf"`
TIME=`date +"%Y-%m-%d"`
#
# set defaults
#
# remember to exclude Subversion data...
GLOBAL_ARGS="-sh"
DU=/usr/bin/du
CUT=/bin/cut
MODE="run"
LOG="/var/log/$NAME.log"
#
# get command line args
while test $# -ne 0 ; do
case $1 in
--help|?|-h)
MODE="help"
;;
esac
shift
done
if test $MODE == "run" ; then
for CONF in $CONFS
do
# this file should define:
# CHECK_DIR - directory tree to check
# ARGS - arguments for the "du" command like --exclude values, etc.
# RECORD_DIR - directory into which to put the resulting du values
# RECORD_FILE - name of the file into which to put the results
source $CONF
echo "sourcing $CONF, executing $DU $GLOBAL_ARGS $ARGS $CHECK_DIR"
DISK_USAGE=`$DU $GLOBAL_ARGS $ARGS $CHECK_DIR | $CUT -f 1`
echo "<du date=\"$TIME\">$DISK_USAGE</du>" >> $RECORD_DIR/$RECORD_FILE
done
else
echo "$NAME, copyright 2005 Egressive Limited, www.egressive.com"
echo ""
echo "Usage: $0 {--last | --this | -h}"
echo "--last - last month's statistics"
echo "--this - the current month's statistics"
echo "-h or --help - this help message"
fi
exit 0