Link to home
Start Free TrialLog in
Avatar of Nitesh Pandey
Nitesh Pandey

asked on

Deleting Symantec files by batch files based on Windows OS edition.

Hello, for one of my customer we are facing low disk space issues on C drives. The servers are windows 2003 and 2008. We found that the virus definition files (approx of 1 GB) exits for 2 days on C drive and thus consumes approx 2 GB of space. I found below script (for windows 2008 & 2003) which deletes the definition files of one day older. I am running these steps as batch file twice (once for windows 2003 & then for windows 2008) as my the path for definition files are different.

By using batch file, is there any that the script will first determine the version on the server and then based on version it will run appropriate command section given below, something like using If\Else? I tried making the batch file script by my own but not able to create it perfectly.


# For windows 2008:
@echo on

for /F "usebackq delims==" %%I in ("servers.txt") do Call :begin %%I
goto :EOF

:begin
set srv=%1
  setlocal enableextensions disabledelayedexpansion
  set "where=\\%srv%\c$\ProgramData\Symantec\Definitions\VirusDefs"
  for /f "skip=1 delims=" %%a in (
    'dir /b /ad /tc /o-d "%where%" ^|findstr /r /c:"^[0-9]*\.[0-9]*$"'
  ) do rmdir /s /q "%where%\%%a"



# For windows 2003:
@echo on

for /F "usebackq delims==" %%I in ("servers.txt") do Call :begin %%I
goto :EOF

:begin
set srv=%1
  setlocal enableextensions disabledelayedexpansion
  set "where=\\%srv%\c$\Program Files\Common Files\Symantec Shared\VirusDefs"
  for /f "skip=1 delims=" %%a in (
    'dir /b /ad /tc /o-d "%where%" ^|findstr /r /c:"^[0-9]*\.[0-9]*$"'
  ) do rmdir /s /q "%where%\%%a"
Avatar of oBdA
oBdA

Try this; it's in test mode and will only display the folders it would delete. Remove the uppercase ECHO in line 15 to run it for real.
The script doesn't bother about the OS version, it just tests for both folders and deletes accordingly if one is found.
@echo off
setlocal

set WhereList="C$\Program Files\Common Files\Symantec Shared\VirusDefs" "C$\ProgramData\Symantec\Definitions\VirusDefs"
for /F "usebackq delims==" %%I in ("servers.txt") do Call :begin %%I
goto :EOF

:begin
set srv=%~1
echo Processing %srv% ...
if exist "\\%srv%\C$" (
	for %%v in (%WhereList%) do (
		if exist "\\%srv%\%%~v" (
			echo ... deleting from '\\%srv%\%%~v'.
			for /f "skip=1 delims=" %%a in ('dir /b /ad /tc /o-d "\\%srv%\%%~v" ^| findstr.exe /r /c:"^[0-9]*\.[0-9]*$"') do (
				ECHO rmdir /s /q "\\%srv%\%%~v\%%a"
			)
			goto :eof
		)
	)
) else (
	echo ... offline or access denied!
)
goto :eof

Open in new window


Edit: added online check.
I had that problem on a 2008 server and decided to move SEP & SEPM to a seperete drive so they would not impact the C drive's space. That worked perfect. We also run into the file problem as you mentioned and clear it out about once a month.

Hope this helps!
Avatar of Nitesh Pandey

ASKER

Hi, on many of the servers we have only one drive so I have to mostly use scripting solution only. I will try to use above script tomorrow on windows servers.
Hi oDBA, I tested above script on servers but the script checks only the first path and not the second path.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Mate, removing "goto :eof" helped in resolving the issue. Thank you very much for your help.