2012-02-06 08:28:40 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
. /etc/alternc/local.sh
|
|
|
|
|
AWK=/usr/bin/awk
|
|
|
|
|
DF=/bin/df
|
|
|
|
|
SED=/bin/sed
|
|
|
|
|
MOUNT=/bin/mount
|
|
|
|
|
QUOTA=/usr/bin/quota
|
|
|
|
|
GREP=/bin/grep
|
|
|
|
|
WC=/usr/bin/wc
|
2012-02-28 14:48:45 +00:00
|
|
|
|
BLKID=/sbin/blkid
|
2012-02-06 08:28:40 +00:00
|
|
|
|
MID=$1
|
|
|
|
|
|
|
|
|
|
if [ "x$MID" == "x" ] ; then
|
|
|
|
|
echo "Usage: quota_get <uid>"
|
|
|
|
|
echo "Get the quota of the AlternC account having uid <uid>"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# The second line is the one interesting
|
|
|
|
|
# We look precisely on the HTML directory. Why ? because it's surely
|
|
|
|
|
# the bigger one, and if someone separate it we need to look this one
|
|
|
|
|
# particulary. It should be interesting to cumulate quota of all mounted directory.
|
2012-02-28 14:48:45 +00:00
|
|
|
|
|
2012-02-06 08:28:40 +00:00
|
|
|
|
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
|
|
|
|
|
|
|
|
|
|
# quota will give over NFS will print the partition using the full NFS name
|
|
|
|
|
# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount
|
|
|
|
|
# to convert DATA_PART if needed.
|
2012-02-28 14:48:45 +00:00
|
|
|
|
|
2012-02-06 08:28:40 +00:00
|
|
|
|
QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"`
|
2012-02-28 14:48:45 +00:00
|
|
|
|
|
2012-02-06 08:28:40 +00:00
|
|
|
|
if [ -z "$QUOTA_PART" ]; then
|
|
|
|
|
QUOTA_PART="$DATA_PART"
|
2012-02-28 14:48:45 +00:00
|
|
|
|
#if the partition is an LVM one we need to adress the partition by its UUID
|
|
|
|
|
UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/')
|
2012-02-06 08:28:40 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2012-02-28 14:48:45 +00:00
|
|
|
|
|
|
|
|
|
# Now we get the quota
|
|
|
|
|
#first by testing if the partition is referenced by UUID
|
|
|
|
|
val=$(sudo quota -A -wg "$MID" |grep "$UUID" | awk '{ print $2 "\n" $3; }')
|
2012-02-06 08:28:40 +00:00
|
|
|
|
if [ -z "$val" ] ; then
|
2012-02-28 14:48:45 +00:00
|
|
|
|
val=$(sudo quota -A -wg "$MID" |grep "$QUOTA_PART" | awk '{ print $2 "\n" $3; }')
|
|
|
|
|
|
|
|
|
|
# If the quota aren't activated, I return something anyway
|
|
|
|
|
if [ -z "$val" ] ; then
|
2012-02-06 08:28:40 +00:00
|
|
|
|
echo -e "0\n0"
|
2012-02-28 14:48:45 +00:00
|
|
|
|
else
|
|
|
|
|
echo -e "0\n0"
|
|
|
|
|
fi
|
|
|
|
|
|
2012-02-06 08:28:40 +00:00
|
|
|
|
else
|
|
|
|
|
echo -e "$val"
|
|
|
|
|
fi
|
2006-05-12 11:17:23 +00:00
|
|
|
|
|