Complete Free Space Report using ONLY builtin commands


G

guard

Consider the following:

01. (((%.GetLogDate%)&(%.GetLogTime%))%.Silent%) ^
02. &(
03. FOR /F %%A IN ('%.eNetView%') DO @(
04. FOR %%B IN (%#UPPER:~4%) DO @(
05. %.Kity% ( (PUSHD \\%%A\%%B$) ^
06. && (%.GetFreeM% %.Silent% ^
07. & CALL ECHO
^%%#LogDate^%%,^%%#LogTime^%%,%%A,%%B,^%%#FreeM^%% ^
08. & POPD
09. )
10. )
11. )
12. )
13.)

The above command provides a date and time coded Free Space Report for ALL
local drives on ALL machines that display in the output of "Net View". It is
assumed that you have access to the administrative shares (C$, D$, etc.).

The command interpreter processes this as one line of code, so it's usually
quite fast. In extremely large networks, the code is easily modified to use
a temporary file for storing the machine names.

*******

The output of this command is a comma separated list that looks like this:

20040416,052826,SERVER1,C,1067
20040416,052826,SERVER1,D,3754
20040416,052826,WORKSTATION1,C,801
20040416,052826,WORKSTATION1,D,1234
20040416,052826,WORKSTATION1,L,5468
20040416,052826,WORKSTATION1,R,0
..
..
..
etc.


The output format is
YYYYMMDD,HHMNSS,Computername,Drive,FreeSpaceInMillionsOfBytes

----------------------------------------------------------------------------
----

How does this work?

.GetLogDate and .GetLogTime retrieve YYYYMMDD and HHMNSS
and save these values in variables named #LogDate and
#LogTime. The .Silent command suppresses the display of
YYYYMMDD and HHMNSS to the console.

The outer loop (FOR /F %%A) sends the output of the command
.eNetView (a formatted list of all systems displayed by the
"Net View" command) to the inner loop (FOR /F %%B).

The inner loop processes a space-delimited list of drive letters
from C through Z and tries to execute a PUSHD command to the
administrative share associated with that drive letter on each
system (\\ComputerName\C$, \\ComputerName\D$, etc.)

The .Kity command (KITY stands for Keep-It-To-Yourself) suppresses
any errors from PUSHD when it does not find, or cannot access, any
of the administrative shares.

If PUSHD is successful, commands after the "&&" are executed for
the machine represented by %%A and the drive letter represented
by %%B.

The command .GetFreeM retrieves the free space, in whole millions
of bytes, that is available on the subject drive and saves this
value in variable #FreeM. Again, we use %.Silent% to suppress
the console display of the free space value.

The CALL ECHO command displays the final output while dynamically
expanding the contents of #LogDate, #LogTime and #FreeM.

Finally POPD returns us to the original directory (only if PUSHD
was successful).

*******
The resources used above are present on EVERY installation of Windows
NT-based systems without adding any additional software to the base OS.
Reference pages follow.

#Constants

#UPPER (http://TheSystemGuard.com/NTCmdLib/Constants)

..Mount/\Commands

.Silent (http://TheSystemGuard.com/MtCmds/RedirRapids)
.Kity (http://TheSystemGuard.com/MtCmds/RedirRapids)

.GetFreeM (http://TheSystemGuard.com/MtCmds/GetValue/GetFreeM.htm)
{Example 2 on the GetFreeM page provides a
color-keyed reference to the code in this post}

.GetLogDate (http://TheSystemGuard.com/MtCmds/GetValue/GetLogDate.htm)
.GetLogTime (http://TheSystemGuard.com/MtCmds/GetValue/GetLogTime.htm)

.eNetView (http://TheSystemGuard.com/MtCmds/NetValue)

Common Command Set - Internal

CALL (http://TheSystemGuard.com/TheGuardBook/CCS-Int/CALL.htm)
ECHO (http://TheSystemGuard.com/TheGuardBook/CCS-Int/ECHO.htm)
FOR (http://TheSystemGuard.com/TheGuardBook/CCS-Int/FOR.htm)
POPD (http://TheSystemGuard.com/TheGuardBook/CCS-Int/POPD.htm)
PUSHD (http://TheSystemGuard.com/TheGuardBook/CCS-Int/PUSHD.htm)
SET (http://TheSystemGuard.com/TheGuardBook/CCS-Int/SET.htm)

!GuardNote about calculating various values using SET /A commands


(http://TheSystemGuard.com/TheGuardBook/CCS-Int/SET.htm#MaxValuesForSet/A)

*******

You can put the entire code in a one-liner:


(((%.GetLogDate%)&(%.GetLogTime%))%.Silent%)&(FOR /F %%A IN ('%.eNetView%')
DO @(FOR %%B IN (%#UPPER:~4%) DO @(%.Kity% ( (PUSHD \\%%A\%%B$) &&
(%.GetFreeM% %.Silent% & CALL ECHO
^%%#LogDate^%%,^%%#LogTime^%%,%%A,%%B,^%%#FreeM^%%& POPD)))))


The main advantage of this approach is that you can now create your own
Mount/\Command called, for example, ".ReportFreeSpace". All you have to do
is store the code in an environment variable under a name that makes sense
to you.

In your actual script, you use one self-documenting command:

%.ReportFreeSpace%

and the entire report is generated.

*******

There's a whole lot more that you can get in a shell script without third
party tools, and without standing on your head! For example the
:System_Info procedure returns the current ServicePack, installed HotFixes
and the IE Version, if installed. A list of installed applications (same as
the list in Control Panel, Add/Remove Programs) is also made available.

:System_Info (http://TheSystemGuard.com/NTCmdLib/Procedures/SI.htm)

*******

For a quick list of all the commands and resources available, see
(http://TheSystemGuard.com/default.asp#MasterCommandList).

*******

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
Ad

Advertisements

B

Bill Stewart

John D. Zanette said:
Consider the following: [...]

Hi John,

(Cross-postings removed [again])

Once again, I must remind you that you are posting to alt.msdos.batch,
which is not a place appropriate for posting cmd.exe-specific code.

Your scripts may be readable to you, but it's tantamount to learning a new
language. Why would we want to do that when we can use VBScript and have
something that's faster and more readable?
CLARITY
Make it clear

Sorry, but again, obfuscated batch files are not "clear."

Regards,

Bill
 
M

Marco Maier Said

guard wrote in message said:
Consider the following:

01. (((%.GetLogDate%)&(%.GetLogTime%))%.Silent%) ^
02. &(
03. FOR /F %%A IN ('%.eNetView%') DO @(
04. FOR %%B IN (%#UPPER:~4%) DO @(
05. %.Kity% ( (PUSHD \\%%A\%%B$) ^
06. && (%.GetFreeM% %.Silent% ^
07. & CALL ECHO
^%%#LogDate^%%,^%%#LogTime^%%,%%A,%%B,^%%#FreeM^%% ^
08. & POPD
09. )
10. )
11. )
12. )
13.)


It is possible without your library using DIR and FOR
 
G

guard

guard wrote



It is possible without your library using DIR and FOR

Of course that's true since the library is composed entirely of native NT
commands and utilities (like FOR, DIR, FindStr.exe, etc.)

The benefits of using Command Libraries are:

COMPATIBILITY, CLARITY and SPEED

The above would be MUCH LONGER and MUCH LESS CLEAR without using the
Mount/\Commands.

*******

For example, you could write some code in C or Assembler to copy a file from
one media to another, but most people prefer to use "COPY Source
Destination" since the COPY command is already written and is always
available. And, of course, it sounds like what it does.

This is the same with commands like ".Silent". Yes, you could use

2>NUL>NUL

or

but Silent is a lot easier to remember and is self-documenting.

*******

Remember, (unlike Java, VBScript, C, .Net, etc.) many shell scripts are
written by persons who never wrote any program code, and probably never
will. They are familiar with batch files and just need/want to get
something done quickly.

While they can almost always get a "FREE" cut and paste solution from
someone, documentation and maintainability are many times not considered due
to time and other constraints.

*******

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
C

Clay Calvert

Remember, (unlike Java, VBScript, C, .Net, etc.) many shell scripts are
written by persons who never wrote any program code, and probably never
will. They are familiar with batch files and just need/want to get
something done quickly.

While they can almost always get a "FREE" cut and paste solution from
someone, documentation and maintainability are many times not considered due
to time and other constraints.

It would not be wise to limit documentation from only one source. It
would make much more sense to use another native command-line language
(though GUI capable as well), such as vbscript. VBscript is actually
free and there are thousands of resources on the web and elsewhere.
Not only that but people can still get a free cut and paste solution
for that language as well.

Clay Calvert
(e-mail address removed)
Replace "W" with "L"
 
Ad

Advertisements

M

Mark V

Thank you no.
LOL! Like he is going to say "sure, you don't really need my
library"!

Never! But it is good to see alternatives posted so that some may
realize. <G>
 
J

Joe Batch

[ Followups set to: alt.msdos.batch.nt ]


:
<very big snip>

Please do not post your messages to a.m.b.
It serves to support your reputation as a spammer, and undermines
your credibility by demonstrating a blatant lack of respect for
newsgroup ettiquette. While posting Infomercials may be questionable
practice, there is no excuse for posting posting NT OS articles in
alt.msdos.batch.
 
M

Marco Maier Said

guard wrote in message said:
Of course that's true since the library is composed entirely of native NT
commands and utilities (like FOR, DIR, FindStr.exe, etc.)

What about this:

fsutil volume diskfree c:
 
G

guard

guard wrote


What about this:

fsutil volume diskfree c:

fsutil works great if:

you are running Windows XP
you want the free space on a local drive

..GetFree (or .GetFreeM) work great if:

you are running Windows NT, 2000, XP or Server 2003
you want the free space on ANY ACCESSIBLE DRIVE
you want the output preformatted and ready to use

*******

GetFree does the following:

Displays the available free bytes on the current drive,
adjusting the output to stay within the limits allowable
by the command shell.

Saves the value in variable %#Free%

Saves the previous value of %#Free%
(if it exists) in %#Previous_#Free%

Sets an errorlevel based on the result

Errorlevels are 0, 1, 2, 3 or 123.

0 = bytes free is 1,000,000,000 or greater
1 = bytes free is at least 1,000,000 but
no more than 999,999,999
2 = bytes free is at least 1,000 but
no more than 999,999
3 = bytes free is at least 1 but
no more than 999
123 = bytes free is 0

*******

..GetFree returns 2000000000 for any drive with free space totaling more than
2 Billion bytes. This lets you reliably compare the result using statements
like:

IF %#Free% GTR nnn [YourCommandHere]

-OR-

SET /A NewBytes=#Free-#Previous_#Free

*******

..GetFreeM drops the last six numbers and gives it's output in Millions of
bytes (not MB) so that free space up to about 1,818 Terabytes can be
manipulated and compared using only shell scripts. This one works great for
things like, for example, network attached storage.

(NOTE: Have you ever noticed how all those slick graphical management
systems always lack "SOMETHING" that makes you have to write a script to get
EXACTLY what you want?!)

*******

..GetFree is in the FREE Advanced NT/2K/XP/K3 Command Library. This library
is completely free for personal or commercial use, contains no
{nag|ad|spy}ware, and provides over 200 resources for writing
self-documenting cross-platform shell scripts.

..GetFreeM is in the Expert Library, which currently has 400+ resources.
It's at (http://NTCmdLib.com). The $9 (or less!) that you pay for the
Expert Library is usually returned to you in saved time within about 15
minutes of use. Not to mention the many Fume Free days you'll enjoy when
you have to modify the script in the future.

*******

Reference pages:

(http://TheSystemGuard.com/TheGuardBook/CCS-Int/IF.htm)
(http://TheSystemGuard.com/TheGuardBook/CCS-Int/SET.htm)

(http://TheSystemGuard.com/MtCmds/GetValue/GetFree.htm)
(http://TheSystemGuard.com/MtCmds/GetValue/GetFreeM.htm)

*******

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 
Ad

Advertisements

M

Marco Maier Said

guard wrote in message said:
.GetFree (or .GetFreeM) work great if:

you are running Windows NT, 2000, XP or Server 2003
you want the free space on ANY ACCESSIBLE DRIVE
you want the output preformatted and ready to use

I have nothing against your methods but vbscript
does the job.For example the Drive object gives
access to the various properties of the local or remote
disk drive.

AvailableSpace property returns the amount of free space:

Set fs = CreateObject("Scripting.FileSystemObject")
Set drv = fs.GetDrive("j")
msgbox drv.AvailableSpace
 
Ad

Advertisements


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