SEARCHSOLARIS.COM
Administrator Tip

SPONSORED BY: PostMasterDirect.com
====================================
Get free offers from reputable merchants for products that you are
interested in. Pick from over 50 categories of interest, modify your
profile at any time to suit your needs, and receive only the email
that interests you when you subscribe today. Just click on the link
below and get your account up and running:
http://searchsolaris.techtarget.com/postmasterDirect/ 
====================================

"Reporting filesystem quotas," by John P. Mulligan

Need to check multiple users' disk usage and quota limits? The
repquota utility is just what you need. This tip, excerpted from
"Solaris 8 Essential Reference," written by John P. Mulligan and
published by New Riders, covers some basics regarding use of the
repquota utility and includes a CGI script that will allow users to
check their quota usage over the Web.

The repquota utility is used to report quota information for multiple
users at a time. For displaying quota information for one user at a
time, the quota command can be used. A filesystem, to be reported,
must be specified unless the -a option is given, in which case all
filesystems with quotas are reported.

Keeping Quotas Private

By default, Solaris allows all users of the system to use the
repquota command. The repquota in /usr/sbin is actually a link to
another file:

     lrwxrwxrwx   1 root          22 Oct 21  1996
     /usr/sbin/repquota -> ../lib/fs/ufs/repquota

The linked file is as follows:

     -r-xr-xr-xn  1 bin         8616 May  2  1996
     ..lib/fs/ufs/repquota

This file is executable by all. This means that all users on the
system will be able to use the repquota utility.

In most cases, this is not a problem, but if for some reason quota
limits and disk usages are to be kept private, change the execute
permission of /usr/lib/fs/repquota as follows (as root):

     chmod 550 /usr/lib/fs/repquota

Option Description 
-a     Report all filesystems with quotas enabled. Filesystems with 
quotas enabled will have a rq in the mntopts field of /etc/vfstab. 

-v     Report quota summaries for all users regardless of disk usage.


The output from repquota is similar to the following:

Block limits                            File limits
User     used   soft   hard  timeleft  used  soft  hard timeleft
smithj --  19  10000  10000               4     0     0
jonesb - 3121  10000  10000              77     0     0
smithk -   39  10000  10000               7     0     0
jonesw - 6393  10000  10000             175     0     0
smithr - 4271  10000  10000             135     0     0

Reporting Quotas over the Web

In some cases, it may be desirable to allow users to check their
quota usage over the Web. There are many ways to do this. The
following CGI script is just one example of the way this can be done.
It assumes that the username has been taken from an HTML form and
passed to the $FORM_uname variable. It also assumes that $HOME is the
base of the URL (such as http://www.somedomain.com). It also uses two
GIF images that are scaled using the WIDTH option in the <IMG> tags
to display a bar graph representation of the quota usage. It should
be noted that this script can be used by any user to check any other
user's quota. If quotas are to be kept private, this script should be
modified.

Caution on CGI Security Issues: Never run CGI scripts as root or
other privileged users on the system. The script included in this
section should probably be run as user nobody.
 
 
Code  
if [ -z "$FORM_uname" ];then
FORM_uname="none"
fi

DATE=`date`
WWW=http://www.somedomain.com
QUOTA=`/usr/sbin/repquota -a| grep $FORM_uname |head -1| awk
--> '{print $4}'`

cat << EOM
<TITLE>Quota for $FORM_uname</TITLE>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=500>
<TR><TD BGCOLOR="#666699">
EOM

#check if there is no quota set for user
if [ -n "$QUOTA" ]; then
QUOTA=`/usr/sbin/repquota -a| grep $FORM_uname|head -1 | awk
-->`{print $5}'`
USED='/usr/sbin/repquota -a| grep $FORM_uname |head -1 | awk
-->`{print $3}'`
PUSED=`expr  $USED * 100 / $QUOTA`
PFREE=`expr 100 - $PUSED`
NAME=`grep $FORM_uname /etc/passwd/head -1|awk '{FS=":";print
-->$5}'`

if [ $PFREE -lt 0 ];then
PFREE=1
fi

if [ -z "$NAME" ];then
NAME=`/usr/sbin/repquota -a| grep $FORM_uname|head -1 | awk
-->'{print $1}'`
fi
cat << EOM
<FONT FACE="Arial, Helvetica" SIZE=5 COLOR="#FFCC00">Quota for
$NAME</FONT>
<CENTER>
<TR><TD BGCOLOR="#FFFFCC">
EOM

if [ $PUSED -gt 100 ]; then
cat << EOM
<FONT FACE="Arial, Helvetica" COLOR="#FF0000" SIZE=4>
YOU ARE OVER YOUR QUOTA LIMIT</FONT>
<P>
<FONT FACE="Arial, Helvetica">Immediately remove unwanted files from 
-->your account in order to decrase your disk
-->usage.</FONT><P>
EOM
fi

cat << EOM
<FONT FACE="Arial, Helvetica">You are currently using $USED KB
-->of disk space in your web account.  That means you are using
-->$PUSED% of your quota limit.<P><BR>
<FONT FACE="Arial Black, Arial, Helvetica"  SIZE=6><CENTER>
-->$PUSED% FULL</FONT>
<BR CLEAR=both>
<IMG BORDER=0 WIDTH=$PUSED HEIGHT=20 HSPACE=0 ALT="$PUSED% 
-->used"
SRC="$WWW/images/blue_button.gif">
<IMG BORDER=0 WIDTH=$PFREE HEIGHT=20 HSPACE=0 ALT="$PFREE%
-->free"
SRC="$WWW/images/blank_button.gif"><P><BR>
EOM
else
cat << EOM
<FONT FACE="Arial" COLOR="#FFCC00" SIZE=5>NO QUOTA</FONT>
<TR><TD BGCOLOR="#FFFFCC">
<FONT FACE="Arial, Helvetica">
No quota set for $FORM_uname. Perhaps you typed the user name
-->incorrectly.
Please resubmit your query.
<BR CLEAR=both><P><BR>
<A HREF="$WWW/quota.html">Try again.</a>
EOM
fi
echo "</TABLE><PRE></CENTER>
echo "$DATE: $REMOTE_HOST checked $FORM_uname" >>
-->$HOME/log/quota.log

The accompanying HTML that includes a form to use is given here:

<FORM METHOD=GET ACTION="/cgi-bin/quotacheck">
<FONT FACE="Arial, Helvetica">
Enter your username: </FONT>
<INPUT NAME="uname" SIZE=15><P>
<CENTER>
<FONT FACE="Arial, Helvetica" SIZE=3>
<INPUT TYPE=RESET VALUE="Reset form">
<INPUT TYPE=SUBMIT VALUE="Press to Check"></FONT>
</FORM>

To learn more about the "Solaris 8 Essential Reference," or to buy
this book, click on
http://www.digitalguru.com/dgstore/product.asp?sku=0735710074&dept%5Fid=242&ac%5Fid=68&accountnumber=&couponnumber=.

Did you like this tip? To rate this and other tips, or to submit a
tip of your own, go to
http://searchsolaris.techtarget.com/tipsIndex/0,289482,sid12_tax281849,00.html.

SPONSORED BY: Whatis.com
====================================
Visit the Web's most comprehensive online technology encyclopedia!
Whatis.com defines more than 2,700 of the most important tech terms
in plain English. Search for a term or navigate by category. Check
out Fast Reference guides for a quick summary of everything from
connection speeds to online color palettes. And don't miss Every File
Format in the World, the Web's largest list of file extensions and
the programs that use them. It's all free at http://whatis.com.
====================================




If you no longer wish to receive this newsletter simply reply to 
this message with "REMOVE" in the subject line.  Or, visit 
http://searchSolaris.techtarget.com/register 
and adjust your subscriptions accordingly. 

If you choose to unsubscribe using our automated processing, you 
must send the "REMOVE" request from the email account to which 
this newsletter was delivered.  Please allow 24 hours for your 
"REMOVE" request to be processed.

Reply via email to