shell / awk question

BURNS gt0178a at prism.gatech.EDU
Fri Oct 19 17:51:03 AEST 1990


in article <4057 at ruuinf.cs.ruu.nl>, emwessel at praxis.cs.ruu.nl (Eric van Wessel) says:
> quota | awk 'BEGIN { FS=" " } { quot=$2 }
> 	     END { printf "%d\n",quot } '
> 				  ^^
> 				  How to make quot known here ? [etc]

The following is a rework of your script. Since my quota(1) reports in the
format:

Your disk usage is approximately       788,480 bytes;
your disk quota is                   2,048,000 bytes.

and my du reports in 1k block sizes, there are minor cosmetic changes,
besides the eval and proper quoting tricks. If your quota(1) supports the
'-qv' option (see man excerpts following script), the first assignment can
be replaced w/the second commented one.

eval QUOTA=`quota | awk 'BEGIN { FS=" " } { quot=$5 }
	     END { print quot }' | sed 's/,//g'`
#eval QUOTA=`quota -qv`
du -s $HOME |
awk 'BEGIN { FS=" " } { printf "\nDiskspace\n";
			printf "---------\n";
			used=$1;
			free='$QUOTA'/1024-used }
     END   { printf "Used : %d kb. (%d%%)\n",used,used*100/('$QUOTA'/1024) ;
	     if (free>=0)
	       printf "Free : %d kb.\n\n",free
	     else printf "Too much : %d kb.\n\n",-free } '

QUOTA(1)         Georgia Institute of Technology         QUOTA(1)



NAME
     quota - display PRISM disk storage usage and maximum limit

SYNOPSIS
     quota [ -q ] [ -u ] [ -v ]

DESCRIPTION
     [...]
OPTIONS
     -q   Display only maximum limit.

     -u   Display only usage.

     -v   Display usage and/or maximum limit value(s) without
          title(s) and without comma formatting the numeric
          value(s).  This is useful for manipulating the value(s)
          in a shell script.

     By default, display usage and then maximum limit, both with
     titles and comma formatting the numeric values.

EXAMPLES
     Here's how to display your disk storage usage and maximum
     limit:
          {hydra:gtuser:22} quota
          Your disk usage is approximately     1,237,792 bytes;
          your disk quota is                   2,048,000 bytes.
          {hydra:gtuser:23}

     Here's how to get your maximum limit into a shell variable
     (assuming your shell is ksh):
          {hydra:gtuser:24} quota=`quota -qv`
          {hydra:gtuser:25} echo $quota
          2048000
          {hydra:gtuser:26}
     [...]
-- 
BURNS,JIM
Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a
Internet: gt0178a at prism.gatech.edu



More information about the Comp.unix.shell mailing list