JSI Tip 4810. How can I implement a share or departmental quota system?


NOTE: For a better shared folder quota, see How do I implement a shared folder quota system?


If you have an environment where a group of users read and write to a shared folder, you can implement a quota system on these shares.

I have scripted Quota.bat to test the quota you set on the share and e-mail as many people as you want when the quota is exceeded.

Quota.bat uses Diruse and BLAT.

To implement Quota.bat for any given share, place a limit.txt file in the shared folder. The limit.txt file has one line of data in the following syntax:

Megabyte_quota Blat_command

where:

Megabyte_quota is the number of megabytes allowed (quota) and Blat_command is the full BLAT command to email quota.log, which Quota.bat will create in the folder, to as many users as you wish, without the subject (-s "This is the Subject"). Here is a sample limit.txt file, for the C:\ZIPNEW folder:

50 blat C:\ZIPNEW\QUOTA.log -to [email protected]

Quota.log will contain a line similar to:

<Drive:>\SharedFolder megabyte Limit=nnn, Used=nnn, Over_Quota=nnn

Remove inherited permissions from limit.txt and grant the System and Administrator Full Control. You may wish to grant selected users read access.

The syntax for using Quota.bat on the 'server' that hosts the shared folder is:

quota <Drive:>\SharedFolder\limit.txt

You can create an allquota.bat file, that contains one line for each limit.txt file, and schedule it to run each hour:

@echo off
call quota <Drive:>\SharedFolder1\limit.txt
call quota <Drive:>\SharedFolder2\limit.txt
call quota <Drive:>\SharedFolder3\limit.txt

Quota.bat contains:

@echo off
setlocal
if \{%1\}==\{\} goto syntax
if not exist %1 goto syntax
FOR /f "Tokens=1*" %%a in ('type %1') do set /a limit=%%a&set blatcmd=%%b
for /f "skip=3 Tokens=1 Delims=. " %%c in ('diruse /m %~DP1') do set /a used=%%c
if %used% LSS %limit% goto done
set /a over=%used% - %limit%
@echo %~DP1 megabyte Limit=%limit%, Used=%used%, Over_Quota=%over% >%~DP1quota.log
%blatcmd% -s "Quota on %~DP1 Exceeded"
:done
endlocal
goto :EOF
:syntax
@echo Syntax: quota limitfile
endlocal


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish