Solved

Batch File For Checking PST Files (timestamp) Over Various Servers

Posted on 2006-07-13
15
746 Views
Last Modified: 2007-12-19

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

0
Comment
Question by:Jeffit
  • 7
  • 7
15 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17100463
Try this:

@echo off

setlocal

set rootDir=D:\USERS
set logFile=D:\USERS\logfile.txt
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17103001
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%\%dirtouse%:
echo =====================================================
echo Working on \\%server%\%share%\%dirtouse%: >> %logfile%
echo ===================================================== >> %logfile%

for /R \\%server%\%share%\%dirtouse% %%f in (*.pst) do echo %%~nxf  %%~dpf  %%~tf  %%~zf >> %logfile%

:end
0
 

Author Comment

by:Jeffit
ID: 17105877

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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17119995
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 :)

0
 

Author Comment

by:Jeffit
ID: 17137966

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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17138453
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.txt

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.

0
 

Author Comment

by:Jeffit
ID: 17162000

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
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 17162021
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 :)

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...

@echo off

setlocal

set dirList=%~1

if "%dirList%"=="" set dirList=dirlist.txt

if not exist "%dirList%" echo %dirList% does not exist.&goto :EOF

set rootDir=D:\USERS
set logFile=D:\USERS\logfile.txt
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 ('type "%dirList%"') 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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17162028
You may find it helpful to review the EE information about rules of conduct and what not:

http://www.experts-exchange.com/help.jsp
0
 

Author Comment

by:Jeffit
ID: 17162589

>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
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17162970
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?
0
 

Author Comment

by:Jeffit
ID: 17164701

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\PST batch\

CMD.exe was strated with the above path as the current directory.

UNC paths are not supported. defaulting to Windows Directory.
---------------------------------

0
 

Author Comment

by:Jeffit
ID: 17164925

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 ?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17165085
0
 

Author Comment

by:Jeffit
ID: 17165565

No need. Fixed by specifying the path of dirlist.

set dirList=D:\THE PATH TO\DIR\THAT\CONTAINS\dirlist.txt

Thanks for all your help on this one.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now