Saved Bookmarks
| 1. |
Solve : MS Dos Deletes files from the directories on one of the servers? |
|
Answer» NEED HELP! This is the commands i have: ECHO OFF set ConfigFile=config.cfg set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt set wmailto=c:\windows\wmailto.exe set "ExistFreeSpace=0" echo Job starting.... >> %loglocation% date /t >> %loglocation% time /t >> %loglocation% :: ** echo CALLING MDMcreateCSVfiles bat file.... >> %loglocation% :: ** Call MDMcreateCSVfiles :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof ) :: *** Call the subroutine; :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo call :ReadConfig email email call :ReadConfig Warningemail Warningemail call :ReadConfig extension extension call :ReadConfig MinFreeSpacePrcnt MinFreeSpace echo Log space on server.... >> %loglocation% call :FreeSpace ExistFreeSpace >> %loglocation% setlocal EnableDelayedExpansion FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i call :ReadConfig Source!ind! source call :ReadConfig OlderThan!ind! olderthan echo Deleting files older than !olderthan! DAYS with the file extension *.%extension% located at !source! >> %loglocation% cd %source% echo . >>%loglocation% ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% echo Delete finished... >> %loglocation% echo. >>%loglocation% ) echo. echo All Deletes complete.... >> %loglocation% call :FreeSpace ExistFreeSpace>> %loglocation% date /t >> %loglocation% time /t >> %loglocation% echo >>%loglocation% if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION ::@SETLOCAL ENABLEEXTENSIONS @CLS @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p @SET /A TotalSpace=!TotalBytes:~0,-9! @SET /A FreeSpace=!FreeBytes:~0,-10! @SET /A TotalUsed=%TotalSpace% - %FreeSpace% @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! @SET /A PercentFree=100-!PercentUsed! @ECHO TOTAL space: %TotalSpace%GB @ECHO Free space: %FreeSpace%GB @ECHO Used space: %TotalUsed%GB @ECHO Percent Used: %PercentUsed%%% @ECHO Percent Free: %PercentFree%%% ::ENDLOCAL ENDLOCAL &set "%~1=%PercentFree%" goto :eof |
|