:: Script created by Paul Kilian
:: Version number is 2.5
:: Any queries regarding this script should be sent to
paul@paulslore.com
:: This script utilises standard Windows 2000/3 command prompt routines to build a
:: status snapshot of any Windows NT or 2000/3 server or workstation. It's intention
:: is to provide a daily report in an HTML web page that can be used to quickly
:: identify problems on the servers or workstations. For more detailed information on the script,
:: please visit the examples page at http://www.paulslore.com.
@echo off
setlocal ENABLEDELAYEDEXPANSION
echo Starting status report
:: Get parameters from INI file
echo Getting settings from INI file
for /f "eol=; tokens=1,2 delims==" %%a in (srvstat.ini) do set %%a=%%b
if "!CustomTitle!" == "" (
if "!AlternateDomain!" == "" (
set Title=Server Status Report for %USERDOMAIN%
) else set Title=Server Status Report for !AlternateDomain!
) else (
for %%m in (!CustomTitle!) do (
set tmpvar=%%m
if /i "!tmpvar!" == "%%USERDOMAIN%%" (
set Title=!Title! %USERDOMAIN%
) else if /i "!tmpvar!" == "%%USERDNSDOMAIN%%" (
set Title=!Title! %USERDNSDOMAIN%
) else set Title=!Title! %%m
)
)
if not exist "!CSSFile!" echo WARNING^^! - the CSS file does not exist
if "!ReportFile!" == "" set ReportFile=srvstat.html
if "!ReportPath!" == "" set ReportPath=Report\
if not "!ReportPath:~-1!" == "\" set ReportPath=!ReportPath!\
if not exist "!ReportPath!" md "!ReportPath!"||(echo Error creating report directory&goto end)
if not exist Temp\nul md Temp||(echo Error creating temp directory&goto end)
for %%a in (*.gif) do if not exist "!ReportPath!%%a" copy /y %%a "!ReportPath!">nul
copy /y !CSSFile! "!ReportPath!">nul
set tempvar=
del /q Temp\*.*
if "!UseLocal!" == "YES" (
echo Building server list
if exist servers.tmp del servers.tmp
if "!AlternateDomain!" == "" (
for /f "tokens=1 delims=\ " %%a in ('net view ^|find "\\"') do >>servers.tmp echo %%a
) else (
for /f "tokens=1 delims=\ " %%a in ('net view /domain:!AlternateDomain!^|find "\\"') do >>servers.tmp echo %%a
)
if not exist servers.tmp (
echo There was an error enumerating the server names. No servers were found.>"!ReportPath!!ReportFile!"
goto archive
) else (
if not "!UseFilter!" == "" (
if "!UseFilter:~0,1!" == "-" (
>servers.txt type servers.tmp|find /i /v "!UseFilter:~1!"
) else >servers.txt type servers.tmp|find /i "!UseFilter!"
) else copy /y servers.tmp servers.txt>nul
del servers.tmp
)
)
for /f %%a in (servers.txt) do (
echo Retrieving raw data from %%a
psinfo -h -d \\%%a >temp\%%a.srv
for /f %%c in ('dumpel -l system -s \\%%a -d 1 -m EventLog -e 6009^|find /c "0"') do >>temp\%%a.srv echo Reboots 24hr: %%c
for /f %%c in ('dumpel -l system -s \\%%a -d 7 -m EventLog -e 6009^|find /c "0"') do >>temp\%%a.srv echo Reboots 7day: %%c
dumpel -l system -s \\%%a -d 1 -t -format dtTISus >temp\%%a24.evt
dumpel -l system -s \\%%a -d 7 -t -format dtTISus >temp\%%a7.evt
for /f "tokens=1,2 delims=:" %%c in ('find /c " 1 " temp\%%a24.evt') do >>temp\%%a.srv echo Errors 24hr: %%d
for /f "tokens=1,2 delims=:" %%c in ('find /c " 1 " temp\%%a7.evt') do >>temp\%%a.srv echo Errors 7day: %%d
for /f "tokens=1,2 delims=:" %%c in ('find /c " 2 " temp\%%a24.evt') do >>temp\%%a.srv echo Warnings 24hr: %%d
for /f "tokens=1,2 delims=:" %%c in ('find /c " 2 " temp\%%a7.evt') do >>temp\%%a.srv echo Warnings 7day: %%d
for /f "skip=1 tokens=2 delims=[]" %%x in ('ping -n 1 %%a') do echo IP Address: %%x >>temp\%%a.srv
)
echo Server Name@Owner@Organization@Type@Platform@Version@Service Pack@Build@System Root@Install Date@IP Address@#CPUs@CPU speed@CPU Type@Memory@Uptime@Reboots 24hrs@7days@Errors 24hrs@7days@Warnings 24hrs@7days>Temp\data.csv
for %%a in (temp\*.srv) do (
set tempvar=
set server=%%a
set server=!server:~5,-4!
echo Collating data for !server!
if "!ShowOSTable!" == "YES" (
for %%b in ("Registered owner","Registered organization","Product type","Kernel version","Product version","Service pack","Kernel build number","System root","Install date","IP Address","Processors","Processor speed","Processor type","Physical memory","Uptime") do (
find /i %%b %%a>nul
if not errorlevel 1 (
for /f "tokens=1* delims=:" %%f in (%%a) do if "%%f" == %%b (
if %%b == "Uptime" (
for /f "tokens=1,3,5 delims= " %%c in ("%%g") do set tempvar=!tempvar!@%%c Days %%d Hrs %%e Mins
) else (
for /f "tokens=* delims= " %%m in ("%%g") do set tmpdata=%%m
set tempvar=!tempvar!@!tmpdata!
)
)
) else (
set tempvar=!tempvar!@Unknown
)
)
)
if "!ShowServerTable!" == "YES" (
for %%e in ("Reboots 24hr","Reboots 7day","Errors 24hr","Errors 7day","Warnings 24hr","Warnings 7day") do (
find /i %%e %%a>nul
if not errorlevel 1 (
for /f "tokens=1* delims=:" %%b in (%%a) do if "%%b" == %%e (
for /f "tokens=* delims= " %%m in ("%%c") do set tmpdata=%%m
set tempvar=!tempvar!@!tmpdata!
)
) else (
set tempvar=!tempvar!@Unknown
)
)
)
echo !server!!tempvar!>>Temp\data.csv
)
:: Build the HTML page
echo Starting to build the report
(
echo ^<html^>
echo ^<head^>
echo ^<title^>!Title!^</title^>
echo ^<link href="!CSSFile!" rel="stylesheet" type="text/css"^>
echo ^</head^>
echo ^<script language="javascript"^>
echo function show^(module^) {
echo var thsize = document.body.style.fontSize;
echo document.getElementById^(module^).style.display='block';
echo document.getElementById^(module + "show"^).style.display='none';
echo document.getElementById^(module + "hide"^).style.display='block';
echo if ^(module == "drvinfo"^) document.getElementById^(module + "head"^).style.fontSize=thsize;
echo }
echo function hide^(module^) {
echo document.getElementById^(module^).style.display = 'none';
echo document.getElementById^(module + "hide"^).style.display='none';
echo document.getElementById^(module + "show"^).style.display='block';
echo if ^(module == "drvinfo"^) document.getElementById^(module + "head"^).style.fontSize='10px';
echo }
echo ^</script^>
echo ^<body^>
echo ^<table width="100%%"^>
echo ^<tr^>
echo ^<th align="left"^>^ !Title!^</th^>
echo ^<td align="right" valign="bottom"^>Report generated at %time:~0,-6% on %date%^</td^>
echo ^</tr^>
echo ^</table^>
)>"!ReportPath!!ReportFile!"
:: OS Info
if not "!ShowOSTable!" == "YES" goto servertable
echo Building report of OS information
(
echo ^<table^>
echo ^<tr^>
echo ^<th^>
echo ^<table width="100%"^>
echo ^<tr^>
echo ^<th^>
if /i !CollapseOSInfo! == YES (
echo ^<img id="osinfoshow" src="down.gif" border="0" onClick="show('osinfo');"^>
echo ^<img id="osinfohide" src="up.gif" border="0" onClick="hide('osinfo');" style="display: none;"^>
) else (
echo ^<img id="osinfoshow" src="down.gif" border="0" onClick="show('osinfo');" style="display: none;"^>
echo ^<img id="osinfohide" src="up.gif" border="0" onClick="hide('osinfo');"^>
)
echo ^</th^>
echo ^<th width="100%%"^>Operating System Information^</th^>
echo ^</tr^>
echo ^</table^>
echo ^</th^>
echo ^</tr^>
echo ^</table^>
if /i !CollapseOSInfo! == YES (
echo ^<div id="osinfo" style="display: none;"^>
) else echo ^<div id="osinfo"^>
echo ^<table^>
)>>"!ReportPath!!ReportFile!"
set count=0
for /f "tokens=1-22 delims=@" %%a in (Temp\data.csv) do (
set /a count=!count! + 1
(
if !count! == 1 (
echo ^<tr^>
) else (
echo ^<tr^>
)
echo ^<td^>%%a^</td^>
echo ^<td^>%%c^</td^>
echo ^<td^>%%e^</td^>
echo ^<td^>%%d^</td^>
echo ^<td align=center^>%%f^</td^>
echo ^<td align=center^>%%g^</td^>
echo ^<td align=center^>%%h^</td^>
echo ^<td^>%%j^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
)
(
echo ^</table^>
echo ^</div^>
)>>"!ReportPath!!ReportFile!"
:: Server Info
:servertable
if not "!ShowServerTable!" == "YES" goto drivetable
echo Building report of server information
(
echo ^<table^>
echo ^<tr^>
echo ^<th^>
echo ^<table^>
echo ^<tr^>
echo ^<th rowspan="2" width="15"^>
if /i !CollapseServerInfo! == YES (
echo ^<img id="srvinfoshow" src="down.gif" border="0" onClick="show('srvinfo');"^>
echo ^<img id="srvinfohide" src="up.gif" border="0" onClick="hide('srvinfo');" style="display: none;"^>
) else (
echo ^<img id="srvinfoshow" src="down.gif" border="0" onClick="show('srvinfo');" style="display: none;"^>
echo ^<img id="srvinfohide" src="up.gif" border="0" onClick="hide('srvinfo');"^>
)
echo ^</th^>
echo ^<th rowspan="2"^>Server Information^</th^>
echo ^<th colspan="3" style="line-height: 1px;"^>^ ^</th^>
echo ^</tr^>
echo ^<tr^>
echo ^<td^>Reboots^</td^>
echo ^<td^>Errors^</td^>
echo ^<td^>Warnings^</td^>
echo ^</tr^>
echo ^</table^>
echo ^</th^>
echo ^</tr^>
echo ^</table^>
if /i !CollapseServerInfo! == YES (
echo ^<div id="srvinfo" style="display: none;"^>
) else echo ^<div id="srvinfo"^>
echo ^<table^>
)>>"!ReportPath!!ReportFile!"
set count=0
for /f "tokens=1-22 delims=@" %%a in (Temp\data.csv) do (
set /a count=!count! + 1
(
if !count! == 1 (
echo ^<tr^>
) else (
echo ^<tr^>
)
echo ^<td^>%%a^</td^>
echo ^<td^>%%k^</td^>
echo ^<td align=center^>%%l^</td^>
echo ^<td align=center^>%%m^</td^>
echo ^<td^>%%n^</td^>
echo ^<td^>%%o^</td^>
echo ^<td^>%%p^</td^>
if "%%q" == "Reboots 24hrs" (
echo ^<td width="40" align="center"^>24hrs^</td^>
) else if %%q GTR !NumReboots1DayAlert! (
echo ^<td align="center"^>%%q^</td^>
) else if %%q GTR !NumReboots1DayWarn! (
echo ^<td align="center"^>%%q^</td^>
) else (
echo ^<td align="center"^>%%q^</td^>
)
if "%%r" == "7days" (
echo ^<td width="40" align="center"^>%%r^</td^>
) else if %%r GTR !NumReboots1WeekAlert! (
echo ^<td align="center"^>%%r^</td^>
) else if %%r GTR !NumReboots1WeekWarn! (
echo ^<td align="center"^>%%r^</td^>
) else (
echo ^<td align="center"^>%%r^</td^>
)
if "%%s" == "Errors 24hrs" (
echo ^<td width="40" align="center"^>24hrs^</td^>
) else if %%s GTR !NumError1DayAlert! (
echo ^<td align="center"^>%%s^</td^>
) else if %%s GTR !NumError1DayWarn! (
echo ^<td align="center"^>%%s^</td^>
) else (
echo ^<td align="center"^>%%s^</td^>
)
if "%%t" == "7days" (
echo ^<td width="40" align="center"^>%%t^</td^>
) else if %%t GTR !NumError1WeekAlert! (
echo ^<td align="center"^>%%t^</td^>
) else if %%t GTR !NumError1WeekWarn! (
echo ^<td align="center"^>%%t^</td^>
) else (
echo ^<td align="center"^>%%t^</td^>
)
if "%%u" == "Warnings 24hrs" (
echo ^<td width="40" align="center"^>24hrs^</td^>
) else if %%u GTR !NumWarnings1DayAlert! (
echo ^<td align="center"^>%%u^</td^>
) else if %%u GTR !NumWarnings1DayWarn! (
echo ^<td align="center"^>%%u^</td^>
) else (
echo ^<td align="center"^>%%u^</td^>
)
if "%%v" == "7days" (
echo ^<td width="41" align="center"^>%%v^</td^>
) else if %%v GTR !NumWarnings1WeekAlert! (
echo ^<td align="center"^>%%v^</td^>
) else if %%v GTR !NumWarnings1WeekWarn! (
echo ^<td align="center"^>%%v^</td^>
) else (
echo ^<td align="center"^>%%v^</td^>
)
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
)
(
echo ^</table^>
echo ^</div^>
)>>"!ReportPath!!ReportFile!"
:drivetable
echo Building report of drive information
(
echo ^<table width="100%%" border="0" cellpadding="0" cellspacing="0"^>
echo ^<tr valign="top"^>
)>>"!ReportPath!!ReportFile!"
:: Drive Status
if not "!ShowDriveTable!" == "YES" goto hotfixtable
(
echo ^<td^>
echo ^<table^>
echo ^<tr^>
echo ^<th^>
echo ^<table^>
echo ^<tr^>
echo ^<th^>
if /i !CollapseDriveInfo! == YES (
echo ^<img id="drvinfoshow" src="down.gif" border="0" onClick="show('drvinfo');"^>
echo ^<img id="drvinfohide" src="up.gif" border="0" onClick="hide('drvinfo');" style="display: none;"^>
) else (
echo ^<img id="drvinfoshow" src="down.gif" border="0" onClick="show('drvinfo');" style="display: none;"^>
echo ^<img id="drvinfohide" src="up.gif" border="0" onClick="hide('drvinfo');"^>
)
echo ^</th^>
if /i !CollapseDriveInfo! == YES (
echo ^<th id="drvinfohead" width="100%%" style="font-size: 10px;"^>Drive Status^</th^>
) else echo ^<th id="drvinfohead" width="100%%"^>Drive Status^</th^>
echo ^</tr^>
echo ^</table^>
echo ^</th^>
echo ^</tr^>
echo ^</table^>
if /i !CollapseDriveInfo! == YES (
echo ^<div id="drvinfo" style="display: none;"^>
) else echo ^<div id="drvinfo"^>
echo ^<table^>
echo ^<tr^>
echo ^<td^>Drive^</td^>
echo ^<td^>FS Type^</td^>
echo ^<td^>MB Total^</td^>
echo ^<td^>MB Free^</td^>
echo ^<td^>%% Free^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
for /f "tokens=1 delims= " %%a in (servers.txt) do (
(
echo ^<tr^>
echo ^<td colspan="5" align="center"^>%%a^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
for /f "usebackq tokens=1-9 delims= " %%b in (`findstr /i /c:": Fixed" temp\%%a.srv`) do (
(
echo ^<tr^>
if "%%j" == "" (
set drsize=%%e %%f
set drfree=%%g %%h
set drpcfree=%%i
) else (
set drsize=%%f %%g
set drfree=%%h %%i
set drpcfree=%%j
)
echo ^<td^>%%b^</td^>
echo ^<td^>%%d^</td^>
echo ^<td^>!drsize!^</td^>
echo ^<td^>!drfree!^</td^>
set calc=!drfree:~0,-5!
set calc=!drpcfree:~0,-1!
if !calc! LSS %DriveSpacePercentAlert% (
echo ^<td align="center"^>!drpcfree!^</td^>
) else if !calc! LSS %DriveSpacePercentWarn% (
echo ^<td align="center"^>!drpcfree!^</td^>
) else (
echo ^<td align="center"^>!drpcfree!^</td^>
)
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
)
)
(
echo ^</table^>
echo ^</div^>
echo ^</td^>
)>>"!ReportPath!!ReportFile!"
:: Hotfixes
:hotfixtable
if "!ShowDriveTable!" == "YES" if "!ShowHotfixTable!" == "YES" echo ^<td width="4"^>^ ^</td^>>>"!ReportPath!!ReportFile!"
if not "!ShowHotfixTable!" == "YES" goto errortable
(
echo ^<td^>
echo ^<table^>
echo ^<tr^>
echo ^<th^>
echo ^<table^>
echo ^<tr^>
echo ^<th^>
if /i !CollapseHotfixInfo! == YES (
echo ^<img id="hfinfoshow" src="down.gif" border="0" onClick="show('hfinfo');"^>
echo ^<img id="hfinfohide" src="up.gif" border="0" onClick="hide('hfinfo');" style="display: none;"^>
) else (
echo ^<img id="hfinfoshow" src="down.gif" border="0" onClick="show('hfinfo');" style="display: none;"^>
echo ^<img id="hfinfohide" src="up.gif" border="0" onClick="hide('hfinfo');"^>
)
echo ^</th^>
echo ^<th width="100%%"^>Installed Hotfixes^</th^>
echo ^</tr^>
echo ^</table^>
echo ^</th^>
echo ^</tr^>
echo ^</table^>
if /i !CollapseHotfixInfo! == YES (
echo ^<div id="hfinfo" style="display: none;"^>
) else echo ^<div id="hfinfo"^>
echo ^<table^>
echo ^<tr^>
echo ^<td^>^ ^</td^>
)>>"!ReportPath!!ReportFile!"
echo Building list of all hotfixes
echo ;All hotfixes found in the environment>Temp\hotfixes.txt
for %%a in (!CriticalHotfixes!) do echo %%a>>Temp\hotfixes.txt
for /f %%a in (servers.txt) do (
for /f "usebackq skip=1 tokens=1* delims= " %%b in (`findstr /c:"/" temp\%%a.srv`) do (
findstr /i "%%b" Temp\hotfixes.txt>nul||echo %%b>>Temp\hotfixes.txt
)
echo ^<td align="center"^>%%a^</td^>>>"!ReportPath!!ReportFile!"
)
echo ^</tr^>>>"!ReportPath!!ReportFile!"
echo Building report of installed hotfixes
for /f %%a in (Temp\hotfixes.txt) do (
set CritHF=
for %%b in (!CriticalHotfixes!) do if /i "%%b" == "%%a" set CritHF=YES
(
echo ^<tr^>
if !CritHF! == YES (
echo ^<td align=center style="background: orange;"^>%%a^</td^>
) else echo ^<td align=center^>%%a^</td^>
)>>"!ReportPath!!ReportFile!"
for /f %%b in (servers.txt) do (
findstr "%%a" temp\%%b.srv>nul||(
if !CritHF! == YES (
echo ^<td align="center"^>-^</td^>>>"!ReportPath!!ReportFile!"
) else echo ^<td align="center"^>-^</td^>>>"!ReportPath!!ReportFile!"
)
for /f "tokens=1,2 delims= " %%c in ('type temp\%%b.srv^|find "%%a"') do echo ^<td align="center"^>%%d^</td^>>>"!ReportPath!!ReportFile!"
)
echo ^</tr^>>>"!ReportPath!!ReportFile!"
)
(
echo ^</table^>
echo ^</div^>
echo ^</td^>
)>>"!ReportPath!!ReportFile!"
:: Errors and Warnings
:errortable
if /i !ShowDriveTable! == YES if /i not !ShowHotfixTable! == YES (
echo ^<td^>>>"!ReportPath!!ReportFile!"
) else (
(
echo ^</tr^>
echo ^</table^>
)>>"!ReportPath!!ReportFile!"
)
if not "%ShowErrorTable%" == "YES" goto endtable
(
echo ^<table^>
echo ^<tr^>
echo ^<th^>
echo ^<table^>
echo ^<tr^>
echo ^<th^>
if /i !CollapseErrorInfo! == YES (
echo ^<img id="erinfoshow" src="down.gif" border="0" onClick="show('erinfo');"^>
echo ^<img id="erinfohide" src="up.gif" border="0" onClick="hide('erinfo');" style="display: none;"^>
) else (
echo ^<img id="erinfoshow" src="down.gif" border="0" onClick="show('erinfo');" style="display: none;"^>
echo ^<img id="erinfohide" src="up.gif" border="0" onClick="hide('erinfo');"^>
)
echo ^</th^>
echo ^<th width="100%%"^>Errors and Warnings ^( Last 24 Hours^)^</th^>
echo ^</tr^>
echo ^</table^>
echo ^</th^>
echo ^</tr^>
echo ^</table^>
if /i !CollapseErrorInfo! == YES (
echo ^<div id="erinfo" style="display: none;"^>
) else echo ^<div id="erinfo"^>
echo ^<table^>
echo ^<tr^>
echo ^<td^>Date^</td^>
echo ^<td^>Time^</td^>
echo ^<td^>ID^</td^>
echo ^<td^>Source^</td^>
echo ^<td^>User^</td^>
echo ^<td^>Detail^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
for /f %%a in (servers.txt) do (
echo Building report of errors and warnings on %%a
(
echo ^<tr^>
echo ^<td colspan="6" align="center"^>%%a^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
for /f "tokens=1-7 delims= " %%b in (temp\%%a24.evt) do (
set ignrevent=
for %%m in (!IgnoreEvents!) do if "%%e" == "%%m" set ignrevent=yes
if /i not "!ignrevent!" == "yes" (
if "%%d" == "2" (
(
echo ^<tr^>
echo ^<td^>%%b^</td^>
echo ^<td^>%%c^</td^>
if /i "!InclEvIDLink!" == "YES" (
echo ^<td align="center"^>%%e^ ^<a href="http://www.eventid.net/display.asp?eventid=%%e" target="_blank"^>^<img src="idinfo.gif" border="0" alt="Click for more information"^>^</a^>^</td^>
) else echo ^<td align="center"^>%%e^</td^>
echo ^<td^>%%f^</td^>
echo ^<td^>%%g^</td^>
echo ^<td^>%%h^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
)
)
)
for /f "tokens=1-7 delims= " %%b in (temp\%%a24.evt) do (
set ignrevent=
for %%m in (!IgnoreEvents!) do if "%%e" == "%%m" set ignrevent=yes
if /i not "!ignrevent!" == "yes" (
if "%%d" == "1" (
(
echo ^<tr^>
echo ^<td^>%%b^</td^>
echo ^<td^>%%c^</td^>
if /i "!InclEvIDLink!" == "YES" (
echo ^<td align="center"^>%%e^ ^<a href="http://www.eventid.net/display.asp?eventid=%%e" target="_blank"^>^<img src="idinfo.gif" border="0" alt="Click for more information"^>^</a^>^</td^>
) else echo ^<td align="center"^>%%e^</td^>
echo ^<td^>%%f^</td^>
echo ^<td^>%%g^</td^>
echo ^<td^>%%h^</td^>
echo ^</tr^>
)>>"!ReportPath!!ReportFile!"
)
)
)
)
echo ^</table^>>>"!ReportPath!!ReportFile!"
if /i !ShowDriveTable! == YES if /i not !ShowHotfixTable! == YES (
(
echo ^</td^>
echo ^</tr^>
echo ^</table^>
)>>"!ReportPath!!ReportFile!"
)
:endtable
(
echo ^</div^>
echo ^<br^>
echo ^<font size="2"^>Archive reports can be found on the ^<a href="archive/archive.html"^>ARCHIVE^</a^> page.
echo ^<br^>
echo The raw data used to generate this page can be downloaded ^<a href="data.txt"^>HERE^</a^>. ^(Tab seperated values, right click the link-choose save as^)^</font^>
echo ^</body^>
echo ^</html^>
)>>"!ReportPath!!ReportFile!"
for /f "tokens=1-25 delims=@" %%a in (Temp\data.csv) do echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y>>Temp\data.txt
copy /y Temp\data.txt "!ReportPath!">nul
if exist Temp\data.txt del Temp\data.txt
echo Report finished
:archive
echo Building archive page
if not exist "!ReportPath!archive\" md "!ReportPath!archive"
for /f "tokens=2,3,4 delims=/ " %%a in ("%date%") do set today=%%c%%b%%a
for /f "tokens=3,4 delims=/ " %%a in ("%date%") do set month=%%b-%%a
if not exist "!ReportPath!archive\!month!\" md "!ReportPath!archive\!month!"
for %%a in (*.gif) do if not exist "!ReportPath!archive\!month!\%%a" copy /y %%a "!ReportPath!archive\!month!\">nul
copy /y !CSSFile! "!ReportPath!archive\">nul
copy /y !CSSFile! "!ReportPath!archive\!month!\">nul
copy /y "!ReportPath!!ReportFile!" "!ReportPath!archive\!month!\stat-!today!.html">nul
:: Build Archive Page
(
echo ^<html^>
echo ^<head^>
echo ^<title^>Server Stats Archive Files^</title^>
echo ^<link href="!CSSFile!" rel="stylesheet" type="text/css"^>
echo ^</head^>
echo ^<body^>
echo ^<center^>^<h2^>Server Status Archive Files^</h2^>^<br^>
echo ^<table^>
)>"!ReportPath!archive\archive.html"
for /f %%a in ('dir /b /ad /o-n "!ReportPath!archive"') do (
(
echo ^<tr^>
echo ^<th^>%%a^</th^>
)>>"!ReportPath!archive\archive.html"
for /f %%b in ('dir /b "!ReportPath!archive\%%a\*.html"') do (
set file=%%b
echo ^<td^>^<a href="%%a/%%b"^>!file:~11,-5!^</a^>^</td^>>>"!ReportPath!archive\archive.html"
)
echo ^<tr^>>>"!ReportPath!archive\archive.html"
)
(
echo ^</table^>
echo ^</center^>
echo ^</body^>
echo ^</html^>
)>>"!ReportPath!archive\archive.html"
echo Archive page finished
:: Copy pages to web folder
:webcopy
if not "%CopyToWeb%" == "YES" goto smtpsend
echo Copying report to web
if "!MapWebFolder!" == "YES" net use !MapDrive! /d && net use !MapDrive! !MapShare!
if not exist "!wwwdir!nul" md "!wwwdir!"
if not exist "!wwwdir!nul" goto smtpsend
copy /y "!ReportPath!!ReportFile!" "!wwwdir!">nul
copy /y "!ReportPath!archive\archive.html" "!wwwdir!">nul
if not exist "!wwwdir!archive\nul" md "!wwwdir!archive"
if not exist "!wwwdir!archive\!month!\nul" md "!wwwdir!archive\!month!"
if not exist "!wwwdir!archive\!month!\idinfo.gif" copy /y idinfo.gif "!wwwdir!archive\!month!">nul
if not exist "!wwwdir!archive\!month!\stat-!today!.html" copy /y "!ReportPath!!ReportFile!" "!wwwdir!archive\!month!\stat-!today!.html">nul
copy /y Temp\data.txt "!wwwdir!">nul
copy /y *.gif "!wwwdir!">nul
echo Copy finished
:smtpsend
if not "%SendSMTP%" == "YES" goto end
echo Emailing report
smtpsend -f!SMTPfrom! -t!SMTPto! -h!SMTPhost! -s!SMTPsubject! -a"!ReportPath!archive\!month!\stat-!today!.html"
:end
del /q Temp\*.*
echo Status report complete
endlocal
Like this:
Like Loading...