Jeffit
asked on
Batch File For Checking PST Files (timestamp) Over Various Servers
I currently have a batch for checking all Pst files that gives me a timestamp. I'm wanting to edit so as to check over a few servers, from a workstation. Trying to ensure that user backups are not older than 7 days.
Currently checks users dir from server and outputs to logfile.txt on server...any help would be appreciated. Thanks
@echo off
for /R D:\USERS %%f in (*.pst) do echo %%~nxf %%~dpf %%~tf %%~zf >> logfile.txt
start logfile.txt
Hmm, I read this slightly differently in that it was more the collecting of the dates from multiple servers into one place than checking the dates, maybe I am wrong and maybe both would be in order.
I came up with this simple batch file. Create a text file called servers.txt laid out as SERVER,SHARE,DIRECTORY, e.g.
MYSERVER,USERS,
MYSERVER,D$,USERS
then save this as checkpst.cmd in the same directory and it will scan down each directory listed and produce the same file format as before but for all servers at the same time.
Steve
@echo off
REM Reads down file servers.txt which contains SERVER,SHARE,DIRECTORY one per line.
SET logfile=logfile.txt
DEL %logfile% 2>nul
for /F "tokens=1,2* delims=," %%A in (servers.txt) do call :process %%A %%B "%%C"
start %logfile%
goto end
:process
set server=%1
set share=%2
set dirtouse=%3
echo Working on \\%server%\%share%\%dirtou se%:
echo ========================== ========== ========== =======
echo Working on \\%server%\%share%\%dirtou se%: >> %logfile%
echo ========================== ========== ========== ======= >> %logfile%
for /R \\%server%\%share%\%dirtou se% %%f in (*.pst) do echo %%~nxf %%~dpf %%~tf %%~zf >> %logfile%
:end
I came up with this simple batch file. Create a text file called servers.txt laid out as SERVER,SHARE,DIRECTORY, e.g.
MYSERVER,USERS,
MYSERVER,D$,USERS
then save this as checkpst.cmd in the same directory and it will scan down each directory listed and produce the same file format as before but for all servers at the same time.
Steve
@echo off
REM Reads down file servers.txt which contains SERVER,SHARE,DIRECTORY one per line.
SET logfile=logfile.txt
DEL %logfile% 2>nul
for /F "tokens=1,2* delims=," %%A in (servers.txt) do call :process %%A %%B "%%C"
start %logfile%
goto end
:process
set server=%1
set share=%2
set dirtouse=%3
echo Working on \\%server%\%share%\%dirtou
echo ==========================
echo Working on \\%server%\%share%\%dirtou
echo ==========================
for /R \\%server%\%share%\%dirtou
:end
ASKER
Thanks guys ! I really appreciate the quick response...these are both fantastic, but I would essentially like to add a check of multiple servers (in dragons to Steves). So a combination of both.
1. The output of Steves, provided a "has hasen't comment...but didn;t specify which ?
2. Just need the information that tells me the user, if it has or hasen't been modified in the past (prob 8 days would be better). Having just "hasen;t been modified would be great, and the date last modified .
3. The key here is a batch that I can run on my workstation and scans multiple servers
4. The first script didn;t seem to take into account any users, who may have archived some email (to pst) 1 day ago, but last modified (backed up) 3 months ago.
Is there a way to modify for this. ie. removals of "archive.pst, xxxxxx.pst" etc.
Cheers
What does this mean?
"has hasen't comment...but didn;t specify which ?
Also:
"hasen;t been modified would be great, and the date last modified .
As for the question: Is there a way to modify for this. ie. removals of "archive.pst, xxxxxx.pst" etc.
Yes, there is a way to do this.
I just need a little better explanation of what you want my batch processing to do to meet your needs. A little gap analysis. My batch processing indicates when a user hasn't updated the server with any .pst files in 7 days.
Thanks :)
"has hasen't comment...but didn;t specify which ?
Also:
"hasen;t been modified would be great, and the date last modified .
As for the question: Is there a way to modify for this. ie. removals of "archive.pst, xxxxxx.pst" etc.
Yes, there is a way to do this.
I just need a little better explanation of what you want my batch processing to do to meet your needs. A little gap analysis. My batch processing indicates when a user hasn't updated the server with any .pst files in 7 days.
Thanks :)
ASKER
Ok,
1. The output result advised "has hasn't"......ive removed the has from the batch and this has reasolved that,...
2. I would like to run this one batch to cover servers x, y and z (same folder location)...not sure how to add the server request
3. Disregard that final comment.
Cheers
You could pass the server name as a command line parameter. You could prompt for the server or encode the servers in a file that the batch file could read.
The command line parameter would be referenced via %~1.
The prompt would look like this:
set /p server=Please enter server:
You'd use a for /f against the server file and loop through the code for the last option.
The dynamic code would set this information:
set rootDir=D:\USERS
set logFile=D:\USERS\logfile.t xt
Or possible just the rootDir variable if you wanted to keep one log file.
If you don't have a drive mapped to the servers, you'd want to get the UNC for the servers:
\\servername\share
Let me know when you get a chance and I can make changes to my batch processing.
The command line parameter would be referenced via %~1.
The prompt would look like this:
set /p server=Please enter server:
You'd use a for /f against the server file and loop through the code for the last option.
The dynamic code would set this information:
set rootDir=D:\USERS
set logFile=D:\USERS\logfile.t
Or possible just the rootDir variable if you wanted to keep one log file.
If you don't have a drive mapped to the servers, you'd want to get the UNC for the servers:
\\servername\share
Let me know when you get a chance and I can make changes to my batch processing.
ASKER
Thanks for your help STEVEGTR, just about there.
Using your script, how do I add a listing of JUST laptop users or narrow the scan to specific laptop users ? I want to be able to place a txt file in the same DIR as the batch file with a listing of usernames or add a list of laptop usernames to the batch or, as mentioned, minus all non laptop users from the scan of D:Users.
Could you possibly show the whole code, with this included. Still learning about batch files, so unsure a line parameters etc. I was unable to add the differen't servers, as i had no idea where to enter the server detail into into the code.?! lets say the server name is NFMH02. so \\NFMH01\USERS. Worst comes to worse, i can always replicate the batch to the other servers and run, as the main thing I need to do is narrow the listing to scan just Laptop users.
Cheers & thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may find it helpful to review the EE information about rules of conduct and what not:
https://www.experts-exchange.com/help.jsp
https://www.experts-exchange.com/help.jsp
ASKER
>This isn't exactly in the scope of the question, but I'll do it if you promise to be a wee bit more responsive to this question. It helps me to help you as I forget things :)
Point taken.
>If you create a file named dirlist.txt or whatever you want and long as you pass the file name as a parameter to the new batch file, this should do the trick. Please let me know ASAP...
Ok. So i've upload the batch. Ensured logfile was in the correct dir, but I am unsure of what needs to be added to the batch with regards to dirlist.txt. I placed the dirlist file (containing the user dir's) into the same location as the batch. Ran the batch and it fails to run. Tried putting dirlist under d:\users, and this also fails to work.
Cheers
The DIRLIST.TXT file contains user names as they appear in in the D:\USERS directory as subdirectories. For instance, if there was a user named STEVE there would be a directory D:\USERS\STEVE.
You place STEVE in the DIRLIST.TXT. If you wanted to include processing for a user JEFF, you'd also include the user named JEFF.
STEVE
JEFF
They map to D:\USERS\STEVE and D:\USERS\JEFF.
You can place this file anywhere, but it work by default in the same directory as where the batch file is. If you wanted to place the DIRLIST.TXT file in D:\USERS. You'd call the batch file with the parameter D:\USERS\DIRLIST.TXT
Here's a tip when working on EE. When you say things like "Ran the batch and it fails to run. Tried putting dirlist under d:\users, and this also fails to work." it helps us (and save gobs of time) if you communicate how it failed?
You place STEVE in the DIRLIST.TXT. If you wanted to include processing for a user JEFF, you'd also include the user named JEFF.
STEVE
JEFF
They map to D:\USERS\STEVE and D:\USERS\JEFF.
You can place this file anywhere, but it work by default in the same directory as where the batch file is. If you wanted to place the DIRLIST.TXT file in D:\USERS. You'd call the batch file with the parameter D:\USERS\DIRLIST.TXT
Here's a tip when working on EE. When you say things like "Ran the batch and it fails to run. Tried putting dirlist under d:\users, and this also fails to work." it helps us (and save gobs of time) if you communicate how it failed?
ASKER
DIRLIST.TXT already contained the names. This part is complete. I just wanted to confirm that.
I couldn't catch the messsage on a remote server, but here is is below from the local server, after attempting to execute the batch.
The DOS window opens, then closes with:
--------------------------
\\SERVERNAMEHER\PATH\OF\PS
CMD.exe was strated with the above path as the current directory.
UNC paths are not supported. defaulting to Windows Directory.
--------------------------
ASKER
Is now working?! It looked to be intermittent this morning, with above message, not to sure why.
Before I close this one & award you the grand prize,..any final thoughts ?
ASKER
No need. Fixed by specifying the path of dirlist.
set dirList=D:\THE PATH TO\DIR\THAT\CONTAINS\dirli
Thanks for all your help on this one.
@echo off
setlocal
set rootDir=D:\USERS
set logFile=D:\USERS\logfile.t
set fileMask=*.pst
set errorsFound=
call :GETDATEPARTS "%date%"
set today=%yy%%mm%%dd%
REM ** Can change this to values greater than 7, for instance 14 is two weeks
call :SUBTRACTDAYS 7
set checkDate=%yy%%mm%%dd%
if exist "%logFile%" del "%logFile%
pushd "%rootDir%"
for /f "delims=" %%a in ('dir /b /ad 2^>NUL') do call :PROCESS "%%a"
popd
if "%errorsFound%"=="Y" echo Found problems. Check %logFile% for details.
goto :EOF
:PROCESS
set freshBackup=
pushd %1
echo Checking %~1...
for /f "delims=" %%a in ('dir /b /s "%fileMask%" 2^>NUL') do call :CHECKFILE "%%a" %%~ta
popd
if "%freshBackup%"=="Y" goto :EOF
(echo %~1 has doesn't have backups that are within a week old.)>>%logFile%
set errorsFound=Y
goto :EOF
:CHECKFILE
call :GETDATEPARTS "%2"
if /i "%yy%%mm%%dd%" GTR "%checkDate%" set freshBackup=Y
goto :EOF
:SUBTRACTDAYS
set dayCnt=%1
if "%dayCnt%"=="" set dayCnt=1
REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100
:CHKDAY
if /I %dd% GTR 0 goto DONESUBTRACT
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yy=%yy% - 1
:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through
:SET31
set /A dd=31 + %dd%
goto CHKDAY
:SET30
set /A dd=30 + %dd%
goto CHKDAY
:LEAPCHK
set /A tt=%yy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yy% %% 400
if %tt%==0 goto SET29
:SET28
set /A dd=28 + %dd%
goto CHKDAY
:SET29
set /A dd=29 + %dd%
goto CHKDAY
:DONESUBTRACT
if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%
goto :EOF
:GETDATEPARTS
set dt=%~1
set tok=1-3
if "%dt:~0,1%" GTR "9" set tok=2-4
set yyyy=
for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)
if not "%yyyy%"=="" set yy=%yyyy%
if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%
goto :EOF
Good Luck,
Steve