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)
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)