Hi,

Although I run a mailserver that handles only about 6K messages a day I found 
that occasionally something went wrong with my sniffer update alhough my script 
reported success.
Turns out there was no error checking in the little part where old file get's 
deleted and the new file is put in (del, ren, ren).
The script uses standard Windows commands available on Windows 2000 and later.
DTLog is a little app I wrote years ago that wil enter a line into a logfile 
and prepend it with date and time info. Replace those lines with whatever suits 
you.

------<quote>--------------------
[.....]
:Replace
rem If we didn't fail then we can go ahead and make the switch.
if exist %IDNAME%.old del %IDNAME%.old
rename %IDNAME%.snf %IDNAME%.old
rename %IDNAME%.tst %IDNAME%.snf

rem Handle any additional successful system updates here (before Done).
%DTLog% %Logfile% Rulefile OK, updated
echo Rulefile OK, updated > %EmailBody%
SET EmailSubj=

:Done
if NOT %1X==X echo %1 >> %EmailBody%
%IMailDir%\imail1 -f %SnifDir%\%EmailBody% -s "Sniffer update on %COMPUTERNAME% 
%EmailSubj%" -t %EmailRpt% -u postmaster -h tio.nl

[.....]
------<quote>--------------------

So I changed this to:
------<quote>--------------------
[.....]
:Replace
rem If we didn't fail then we can go ahead and make the switch.
rem First delete any existing old file
if exist %IDNAME%.old del %IDNAME%.old
Set Err=%ErrorLevel%
IF %Err% GEQ 1 Goto ErrDelOld
rem Old file is gone, swap out current rulefile
rename %IDNAME%.snf %IDNAME%.old
Set Err=%ErrorLevel%
IF %Err% GEQ 1 Goto ErrSnf2Old
Rem Now we don't have any rulefile, get the new one in
rename %IDNAME%.tst %IDNAME%.snf
Set Err=%ErrorLevel%
IF %Err% GEQ 1 Goto ErrTst2Snf
Goto ReplaceOk

:ErrDelOld
%DTLog% %Logfile% Error %Err% deleting %IDNAME%.old !!!
Echo Error deleting %IDNAME%.old !!! > %EmailBody%
goto Done

:ErrSnf2Old
%DTLog% %Logfile% Error %Err% renaming %IDNAME%.snf to %IDNAME%.old !!!
Echo Error renaming %IDNAME%.snf to %IDNAME%.old !!! > %EmailBody%
Echo Old rulefile still in place >> %EmailBody%
Goto Done

:ErrTst2Snf
%DTLog% %Logfile% Error %Err% renaming %IDNAME%.tst to %IDNAME%.snf !!!
Echo Error renaming %IDNAME%.tst to %IDNAME%.snf !!! > %EmailBody%
Echo NO RULEFILE !!! >> %EmailBody%
SET EmailSubj=PANIC!!!
rem Might even send SMS Alert here
Goto Done

:ReplaceOk
rem Handle any additional successful system updates here (before Done).
%DTLog% %Logfile% Rulefile OK, updated
echo Rulefile OK, updated > %EmailBody%
SET EmailSubj=

:Done
if NOT %1X==X echo %1 >> %EmailBody%
%IMailDir%\imail1 -f %SnifDir%\%EmailBody% -s "Sniffer update on %COMPUTERNAME% 
%EmailSubj%" -t %EmailRpt% -u postmaster -h tio.nl

[.....]
------<quote>--------------------

Please feel free to use this as a guideline to update your own scripts.
Pete, you might want to think about updating the sample script on the website

p.s. For whatever reason the line "if exist %IDNAME%.old del %IDNAME%.old" in 
this mail script will report errorlevel 1 at my server when the *.old file does 
not exist eventhough another script with exactly the same line on the same 
server DOES work correctly. If I ever find out why..... :-(


Met vriendelijke groet,
Bonno Bloksma
hoofd systeembeheer



tio hogeschool hotelmanagement en toerisme 
begijnenhof 8-12 / 5611 el eindhoven
t 040 296 28 28 / f 040 237 35 20
[EMAIL PROTECTED]  / www.tio.nl 

Reply via email to