 |
The Unofficial Alabanza Forums To access Hidden Members' forums, fill out membership page
|
| View previous topic :: View next topic |
| Author |
Message |
Arf Official Test Penquin

Joined: 09 Apr 2002 Posts: 8327 Location: IDAHO, USA
|
Posted: Tue Jun 08, 2010 9:37 am Post subject: cPanel Quota Management during package changes |
|
|
I've been hunkered down writing code again. It's been a while since I've been able to contribute because I've been learning how cPanel works or in this case, doesn't work and needs a fix. So, here's one of my first contributions to the cause. It's good to be coding again.
Problem: When you edit a hosting package in cPanel, WHM resets all quotas to their default even if the clients using that package have purchased disk space ala-cart.
Solution: I've developed two programs QuotaRecord and QuotaReset that automate the process of resetting all the quotas for each client.
QuotaRecord creates a database of all the quotas for all the clients on the server. You run this program prior to making package changes.
QuotaReset resets all the quotas back to their custom levels after you've made changes in a specific package.
Caveat: Um, not sure if this needs to be said, but if the change you're making in the WHM alters the disk space quota for the package, you wouldn't want to use QuotaReset because it would reset the quota back to the level prior to you making the desired change.
Disclaimer: There are not warranties or guarantees that the code below will do or fail to do anything. No support is provided. No assurance that they won't do damage or bring down the fire of wrath. Use at your own risk. And of course, bla bla bla. _________________ Thomas
ez2ba.com (easy to be a dot-com)
Last edited by Arf on Tue Jun 08, 2010 9:41 am; edited 1 time in total |
|
| Back to top |
|
 |
Arf Official Test Penquin

Joined: 09 Apr 2002 Posts: 8327 Location: IDAHO, USA
|
Posted: Tue Jun 08, 2010 9:38 am Post subject: |
|
|
QuotaRecord
| Code: | #!/bin/bash
# quotarecord by Thomas Leo 6/2010. Version 1.0
# stores a record of the user name and his quota in megabytes info /root/tmp/quotarecord.txt
# This program is designed to be used prior to editing a hosting package in cPanel where
# all the user quotas will be set back to their orignal default and any extra disk space
# on those accounts is removed. This program makes a record of the current quotas prior
# to the resetting of the hosting package so that another program, quotarepair, can be run
# to reset all account quotas back to their individual custom quotas.
# format of output file: username MEGS BYTES
# example: smith 100 102400
# DISKPARTITION - the specific disk partition to check. Hint: use the "df" command, find
# the /home directory on right columnm, partition is on left. Example: "/dev/sda8"
DISKPARTITION="/dev/sda8"
# Just chmod 700 and run.
# Data collected it put into a file /root/tmp/quotarecord.txt
##########################################################################################
# Make /root/tmp if doesn't exist.
if [ ! -d /root/tmp ]; then mkdir /root/tmp; fi
# clear /root/tmp/quotarecord.txt
> /root/tmp/quotarecord.txt
# filter out all the extra stuff from the repquota command.
repquota $DISKPARTITION | awk '{print $1"\t "$4}' | grep -v "^#" | grep "0$" | grep -v " 0$" > /root/tmp/rawquotalist
# digest the info.
while read LINE; do
USERNAME=`echo $LINE | awk '{print $1}'`
BYTES=`echo $LINE | awk '{print $2}'`
MEGS=`echo $((BYTES/1024))`
echo "$USERNAME $MEGS $BYTES" | tee -a /root/tmp/quotarecord.txt
done < /root/tmp/rawquotalist
# rm /root/tmp/quotarecord.txt DO NOT REMOVE as this is used by quoterepair program.
rm /root/tmp/rawquotalist
echo "Thank you for using $0 output is at /root/tmp/quotarecord.txt -- Thomas" |
|
|
| Back to top |
|
 |
Arf Official Test Penquin

Joined: 09 Apr 2002 Posts: 8327 Location: IDAHO, USA
|
Posted: Tue Jun 08, 2010 9:38 am Post subject: |
|
|
QuotaReset
I didn't mention it because I'd rather people realize after the first run that unless you put -L in the command line the program will just do a test run and made no changes. You would discover that upon first run.
| Code: | #!/bin/bash
# quotareset by Thomas Leo 6/2010. Version 1.0
# Restores quotas for all account according to information in /root/tmp/quotarecord.txt
# as created by companion program quotarecord.
# This program is designed to be used after editing a hosting package in cPanel where
# all the user quotas will be set back to their orignal default and any extra disk space
# on those accounts is removed. This program resets all the current quotas to what they
# were prior to the resetting of the hosting package
# DISKPARTITION - the specific disk partition to check. Hint: use the "df" command, find
# the /home directory on right columnm, partition is on left. Example: "/dev/sda8"
# NOTE: THIS SHOULD MATCH $DISKPARTITION in quotarecord
DISKPARTITION="/dev/sda8"
# Just chmod 700 and run. No variables need to be set. This program requires data collected
# by it's companion program quotarecord to be put into a file
# /root/tmp/quotarecord.txt
##########################################################################################
# idiot check
if [ ! -f /root/tmp/quotarecord.txt ]; then
echo "Required file does not exist: /root/tmp/quotarecord.txt. That file is created by quotarecord."
echo "I'm sorry, I cannot reset quotas without that file... exiting"
exit
fi
while read LINE; do
USERNAME=`echo $LINE | awk '{print $1}'`
OLDMEGS=`echo $LINE | awk '{print $2}'`
OLDBYTES=`echo $LINE | awk '{print $3}'`
CURRENTBYTES=`quota $USERNAME | grep $DISKPARTITION | awk '{print $3}'`
CURRENTMEGS=`echo $(($CURRENTBYTES/1024))`
# Don't bother changing if old and current quota is the same.
if [ $CURRENTMEGS != $OLDMEGS ]; then
echo -e "USER NAME: $USERNAME\n Old Quota: $OLDMEGS - Current Quota: $CURRENTMEGS "
echo "Resetting quota for $USERNAME to $OLDMEGS"
if [ "$1" = "-L" ]; then
M="M" #Required by the use of the following variablesa
/scripts/editquota $USERNAME $OLDMEGS$M
else
echo " ::: TEST MODE ON: To turn test mode off you must use -L in the command line. No changes"
fi
fi
done < /root/tmp/quotarecord.txt
echo "Thank you for using $0 -- Thomas" |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|