Help about a script .bat

Joined
May 28, 2007
Messages
1
Reaction score
0
Hello

I hope somebody can help me.

I have to do a script that provides a quota checking for disk space in use.

This script should run in windows xp.

I found the following scripts that make it (they were written for Windows NT), however I don´t know if they can run in Windows XP and how to run them for example if they need to be located in a determinate path, how to defne the parameters in order to run them.


I would like somebody can explain me how to use this, please :)



Script name: usrquota

@echo OFF
@if not "%ECHO%"=="" echo %ECHO%

rem $Workfile: usrquota.bat $ $Revision: 1 $ $Date: 25/05/2007 9:51a $
rem $Archive: C:\PROJECTS\usrquota.bat $
rem Set local scope and call MAIN procedure
setlocal & pushd & set RET=
set SCRIPTNAME=%~N0
set SCRIPTPATH=%~F0
if "%DEBUG%"=="1" (set TRACE=echo) else (set TRACE=rem)
call _mtplib :INIT %SCRIPTPATH%
if /i {%1}=={/help} (call :HELP %2) & (goto :HELPEXIT)
if /i {%1}=={/?} (call :HELP %2) & (goto :HELPEXIT)
call :MAIN %*
:HELPEXIT
popd & endlocal & set RET=%RET%
goto :EOF

rem //////////////////////////////////////////////////////////////////////////////////////////////////////////////
rem HELP procedure
rem display brief on line help
rem
:HELP
if define TRACE %TRACE% [proc %0 %*]
echo Syntax: USRQUOTA dir-list [/QUOTA] [DOMAIN] [/oVER]
echo Check disk quota usage per user.
echo .
echo dir-list
echo One more directories to check (UNC names are ok).
echo /QUOTA
echo only report on users with restricted quotas.
echo /DOMAIN
echo Gets quota info from domain (def: local computer).
echo /OVER
echo Only display users over quota limit.
echo .
echo To specify a quota for a user account, add the text #QUOTA:nnn#
echo to the comment (description) field of the user account, where
echo nnn in the user quota in megabytes
goto :EOF
rem /////////////////////////////////////////////////////////////////////////////////////////////////////////////
rem MAIN procedure
rem
:MAIN
if defined TRACE %TRACE% [proc %0 %*]
rem if no arguments, we default to displayong help
if {%1}=={} (call :HELP) & (goto :EOF)
rem Parse command line and setup variables
set CMDLINE=%*
call _mtplib :pARSECMDLINE 0
if %CMDARGCOUNT% LSS 1 (call :HELP) & (goto :EOF)
call _mtplib :FINDSWITCH /quota
if not "%RET%"=="0" (set QUOTASW=1) else (set QUOTASW =0)
call _mtplib :FINDSWITCH /domain
if not "%RET%"=="0" (set DOMAINSW=/DOMAIN) else (set OVERSW=0)

rem Get temporary filenames
call _mtplib :GETTEMPNAME
set TEMPALL=%RET%
call _mtplib :GETTEMPNAME
set TEMPONE=%RET%

rem Accumulate disk usage results into temporary file
set /a IX=1
:DISKUSELOOP
call _mtplib :GETARG %IX%
if "%RET%"=="" goto :DISKUSELOOPEND
set /a IX+=1
if exist "%TEMPONE%" del "%TEMPONE%"
diskuse "%RET%" /T /S /_F:%TEMPONE% >nul
type %TEMPONE% | find ",">>"%TEMPÁLL%"
goto :DISKUSELOOP
:DISKUSELOOPEND

rem Now parse the results file
set USERNAME =
echo UserName Used Quota Percent
echo ..................................................................................................
for /f "tokens=1-3 delims=," %%I in ('type %TEMPALL% ^| sort') do call
:ADDQUOTA %%I%%J %%K
call :SHOWUSERINFO

rem Delete temporary files
del %TEMPALL%
del %TEMPONE%
goto :EOF
rem ////////////////////////////////////////////////////////////////////////////////////////////////////////////

rem ADDQUOTA procedure
rem Add a line of quota information
rem
rem Arguments: %1=User name
rem %2=quota bytes
rem
:ADDQUOTA
rem Handle switch to new username
if not {%1}=={%username} (
(call :SHOWUSERINFO)
(set USERNAME=%1)
(set /a MBTOTAL=0)
)
set /a MBTOTAL+%2/1048576
goto :EOF

rem /////////////////////////////////////////////////////////////////////////////////////////////////////////
rem SHOWUSERINFO procedure
rem Display accumulated results for one user
rem
rem Arguments: USERNAME= user name
rem MBTOTAL = total mbytes for this user
rem
:SHOWUSERINFO
if defined TRACE %TRACE% [proc %0 %*]
if "%USERNAME%"=="" goto :EOF

rem Get quota information for user
set MBQUOTA=
set /a PERCENT=0
for /f "tokens=2 delims=/" %%I in ("%USERNAME%") do set USER=%%I
for /f "tokens=*" %%I in ('net user %USER% %DOMAINSW% 2^>nul ^| find
/i "#QUOTA:"') do set MBQUOTA=%%I
for /f "tokens=2 delims=#" %%I in ("%MBQUOTA%") do set MBQUOTA=%%I
for /f "tokens=2 delims:" %%I in ("%MBQUOTA%") do set MBQUOTA=%%I
if not "%MBQUOTA%"=="set /a PERCENT=MBTOTAL*100/MBQUOTA

rem Filter display based upon switches
set T5
if "%MBQUOTA%"=="" if "%QUOTASW%"=="1" goto :EOF
if not "%MBQUOTA%"=="" if %percent% LEQ 100 if "%OVERSW%"=="1" goto
:EOF
if not "%MBQUOTA%"=="" if %PERCENT% GTR 100 set T5=***
if "%MBQUOTA%"=="" set PERCENT=---

rem The following SET commands are all space-padded to here ---->
set T1=%USERNAME%
set T2=%MBTOTAL%
set T3=%MBQUOTA%
set T4=%PERCENT%%%

rem Do not pad these SET commands
set T1=%T1:-0,30%
set T2=%T2:-0,8%
set T3=%T3:-0,8%
set T4=%T4:-0,8%
echo %T1% %T2% %T3% %T4% %T5%
goto :EOF

rem /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rem Additional procedures go here ...

rem These must be the FINAL LINES in the script ....
:DOSEXIT
echo This script requires Windows NT
rem ////////////////////////////////////////////////////////////////////////////////////////////////////////////////




script name: _mtplib.bat

@echo OFF
@if not "%ECHO%"=="" echo %ECHO%

rem $Workfile: _mtplib.bat $ $Revision: 1 $ $Date: 25/05/2007 9:51a $
rem $Archive: C:\PROJECTS\_mtplib.bat $
rem If no arguments, show version information and exit
if "%1"=="" (
(echo Script MTP Script Library [%0] $Revision: 2 $)
(goto :EOF)
)
rem At least one argument, so dispatch to procedure
set _PROC=%1
shift /1
goto %_PROC%

rem ////////////////////////////////////////////////////////////////////////
rem INIT procedure
rem Must be called in local state before other procs are used
rem
:INIT
if defined TRACE %TRACE% [proc %0 %*]
goto :EOF

rem ////////////////////////////////////////////////////////////////////////
rem VARDEL procedure
rem Delete multiple variables by prefix
rem
rem Arguments: %1=variable name prefix
rem
:VARDEL
if defined TRACE %TRACE% [proc %0 %*]
for /f "tokens=1 delims==" %%I in ('set %1 2^>nul') do set %%I=
goto :EOF

rem ////////////////////////////////////////////////////////////////////////
rem PARSECMDLINE procedure
rem Parse a command line into switches and args
rem
rem Arguments: CMDLINE=command text to parse
rem %1=0 for new parse (def) or 1 to append to existing
rem
rem Returns: CMDARG_n=arguments, CMDSW_n=switches
rem CMDARGCOUNT=arg count, CMDSWCOUNT=switch count
rem RET=total number of args processed
rem
:pARSECMDLINE
if defined TRACE %TRACE% [proc %0 %*]
if not {%1}=={1} (
(call :VARDEL CMDARG_)
(call :VARDEL CMDSW_)
(set /a CMDARGCOUNT=0)
(set /a CMDSWCOUNT=0)
)
set /a RET=0
call:pARSECMDLINE1 %CMDLINE%
set _MTPLIB_T1=
goto :EOF
:pARSECMDLINE1
if {%1}=={} goto :EOF
set _MTPLIB_T1=%1
set _MTPLIB_T1=%_MTPLIB_T1:"=%
set /a RET+=1
shift /1
if "%_MTPLIB_T1:~0,1%"=="/" goto :pARSECMDLINESW
if "%_MTPLIB_T1:~0,1%"=="-" goto :pARSECMDLINESW
set /a CMDARGCOUNT+=1
set CMDARG_%CMDARGCOUNT%=%_MTPLIB_T1%
goto :pARSECMDLINE1
:pARSECMDLINESW
set /a CMDSWCOUNT+=1
set CMDSW_%CMDSWCOUNT%=%_MTPLIB_T1%
goto :pARSECMDLINE1
goto :EOF
rem //////////////////////////////////////////////////////////////////////
rem GETARG procedure
rem Get a parsed argument by index
rem
rem Arguments: %1=argument index (1st arg has index 1)
rem
rem Returns: RET=argument text or empty if no argument
rem
:GETARG
if defined TRACE %TRACE% [proc %0 %*]
set RET=
if %1 GTR %CMDARGCOUNT% goto :EOF
if %1 EQU 0 goto :EOF
if not defined CMDARG_%1 goto :EOF
set RET=%%CMARG_%1%%
call :RESOLVE
goto :EOF
rem //////////////////////////////////////////////////////////////////////
rem FINDSWITCH procedure
rem Finds the index of the name switch
rem
rem Arguments: %1=switch name
rem %2=search start index (def: 1)
rem
rem Returns: RET=index (o if not found)
rem RETV=switch value (text after colon)
rem
:FINDSWITCH
if defined TRACE %TRACE% [proc %0 %*]
if {%2}=={} (set /a _MTPLIB_T4=1) else (set /a _MTPLIB_T4=%2)
:FINDSWITCHLOOP
call :GETSWITCH %_MTPLIB_T4%
if "%RET%"=="" (set RET=0) & (goto :FINDSWITCHEND)
if /i "%RET%"=="%1" (set RET=%_MTPLIB_T4%) & (goto :FINDSWITCHEND)
(set /a _MTPLIB_T4+=1
goto : FINDSWITCHLOOP
:FINDSWITCHEND
set _MTPLIB_T4=
goto :EOF
rem ///////////////////////////////////////////////////////////////////////
rem RESOLVE procedure
rem Fully resolve all indirect variable references in RET variable
rem
rem Arguments: RET=value to resolve
rem
rem Returns: RET=as passed in, with references resolved
rem
:RESOLVE
if defined TRACE %TRACE% [proc %0 %*]
:RESOLVELOOP
if "%RET%"=="" goto :EOF
set RET1=%RET%
for /f "tokens=*" %%I in ('echo %RET%') do set RET=%%I
if not "%RET%"=="%RET1%" goto :RESOLVELOOP
goto :EOF
rem ///////////////////////////////////////////////////////////////////////
rem GETTEMPNAME procedure
rem Create a temporary file name
rem
rem Returns: RET=Temporary file name
rem
:GETTEMPNAME
if defined TRACE %TRACE% [proc %0 %*]
if not defined _MTPLIB_NEXTTEMP set /a _MTPLIB_NEXTTEMP=1
if defined TEMP (
(set RET=%TEMP%)
) else if defined TMP (
(set RET=%TMP%)
) else (set RET=%SystemRoot%)
:GETTEMPNAMELOOP
set /a _MTPLIB_NEXTTEMP=_MTPLIB_NEXTTEMP * 214013 + 2531011
SET /a _MTPLIB_T1=_MTPLIB_NEXTTEMP ^>^> 16 ^& 0x7FFF
set RET=%RET%\~SH%_MTPLIB_T1%.tmp
if exist "%RET%" goto :GETTEMPNAMELOOP
set _MTPLIB_T1
goto :EOF
rem These must be the FINAL LINES in the script ...
:DOSEXIT
echo This script requires Windows NT
rem ///////////////////////////////////////////////////////////////////////
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top