Home / Microsoft / Microsoft DOS / Search Files on multiple servers
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2  All - (Bottom) Print
Author Topic: Search Files on multiple servers  (Read 1426 times)
captedgar
Topic Starter
Rookie



Posts: 24


« on: December 01, 2009, 05:55:46 AM »

Hi there

can anyone help me or guide me to do the following please?

I need a batch file to search for a specific file on multiple servers, we have about 100 servers.
This batch file should accept the file to search include the path name and if the file exists then it needs to write to a log file.

please help
IP logged
gpl
Apprentice



Thanked: 25
Posts: 547




« Reply #1 on: December 01, 2009, 06:46:49 AM »

What do you have so far ?
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #2 on: December 01, 2009, 07:27:59 AM »

I havne't got anything. can u please guide me. very much willing to learn
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #3 on: December 01, 2009, 08:04:44 AM »

Hi there

I have got something to start with i.e.

@echo off
dir \\<Servername>\c$ | findstr "\<gegre\>"


Can anyone please help or guide
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #4 on: December 01, 2009, 08:25:37 AM »

I have made some more progress please help

@echo off
for %%a in (
servername1
servername2
servername3
servername4
servername40
) do if exist "\\%%a\sharename\path to look in\file to look for.txt" (
echo found the file on server %%a >>"file.log"
)
IP logged
Salmon Trout
Sage



Thanked: 546
Posts: 7,952

Computer: Specs
Experience: Beginner
OS: Unknown

1
« Reply #5 on: December 01, 2009, 09:43:39 AM »

And did it work?
IP logged


Proud to be European
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #6 on: December 01, 2009, 09:53:57 AM »

Hi Salmon

it hasn't worked. can u please guide me
IP logged
wbrost
Intermediate



Thanked: 11
Posts: 215




« Reply #7 on: December 01, 2009, 12:24:30 PM »

are you getting any error messages? Lets try and take out the for loop and just run the command on a system you know has the file.

IF EXIST "\\servername1\sharename\path to look in\file to look for.txt" ECHO found the file on server servername1 >>"file.log"

let us know if you get a result on this method.
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #8 on: December 01, 2009, 03:41:47 PM »

Hi wbrost

The output on the logfile read as follows:

found the file on server <servername> which means the script works to find the file on the particular servers. Now i have edited, the script to search on multiple servers and my script looks as follows.

 IF EXIST "\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt" ECHO found the file on server servernameA >>"file.log"
 IF EXIST "\\servernameB\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt" ECHO found the file on server servernameB>>"file.log"
 IF EXIST "\\servernameC\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt" ECHO found the file on server servernameC>>"file.log"
 IF EXIST "\\servernameD\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt" ECHO found the file on server servernameD>>"file.log"
 IF EXIST "\\servernameE\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt" ECHO found the file on server servernameE>>"file.log"

This is untested. So i have the following questions, do i need to include separators like commas or brackets in between each lines for this script to work
Also can u please guide me to add a delete functionality to the batch script above which will delete the testing file above once i found it on the relevent server.

IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #9 on: December 02, 2009, 05:20:08 AM »

IF EXIST "\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt"
ECHO found the file on server servernameA >>"file.log"&del
"\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt"


can anyone guide me how to change the above script so that once the file is found, it would then insert a permission to delete or leave the file as it is please?
IP logged
wbrost
Intermediate



Thanked: 11
Posts: 215




« Reply #10 on: December 02, 2009, 08:54:55 AM »

are you asking to have the batch ask if you would like to delete the file Or, just have the file deleted if found?
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #11 on: December 02, 2009, 09:00:44 AM »

Hi wbrost

I have the following batch file which i have managed to come upto. find below

set "file=\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr
\testing.txt"
set "answer="
if exist "%file%" (
echo found the file on server servernameA
echo found the file on server servernameA >>"file.log"
set /p "answer=Delete the file? [y/N] :"
)
if /i "%answer%"=="y" del "%file%"

I need to change the functionality of the above script to search a file if the path is not specified. We have 2 drive on about 40 servers, so lets assume we want to search a file that could exist anywhere either in c drive or g drive. could even be in sub folders. the script should find
this file and ask before deleting. please help

IP logged
wbrost
Intermediate



Thanked: 11
Posts: 215




« Reply #12 on: December 02, 2009, 11:27:01 AM »

here is a batch that will list the files in each folder and sub folder. You should be able to incorporate it into your script.

Code: [Select]
@ECHO OFF
CLS

REM THIS WILL SCAN THE CURRENT FOLDER AND RETURN SUB-FOLDERS TO A TEXT FILE
CD %CD%
DIR /b /s /ad>"%TEMP%\DIRTEST.TXT"

REM USE DIRTEST.TXT IN A FOR LOOP
FOR /f "delims==" %%A in (C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp\DIRTEST.TXT) DO SET A=%%A& CALL :DIR %%A


CLS
IF EXIST "%TEMP%\DIRTEST.TXT" DEL "%TEMP%\DIRTEST.TXT"
        IF EXIST "%TEMP%\DIRFILE.TXT" DEL "%TEMP%\DIRFILE.TXT"
ECHO JOB COMPLETE.....
Pause
GOTO END

:DIR

REM THIS WILL SCAN THE CURRENT FOLDER AND RETURN FILES TO A TEXT FILE

CD\
CD "%A%"

DIR /b /a-d>"%TEMP%\DIRFILE.TXT"

REM USE DIRTEST.TXT IN A FOR LOOP
FOR /f "delims==" %%A in (C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp\DIRFILE.TXT) DO SET FILE=%%A& CALL :DIRFILE %%A

:DIRFILE
ECHO %FILE%
PAUSE

:END

let me know if you have any questions.
IP logged
captedgar
Topic Starter
Rookie



Posts: 24


« Reply #13 on: December 03, 2009, 07:24:58 AM »

Sorry wb rost the batch file that i have got already performs the function of finding files. i need to find the following information to insert to my batch file below

A functionality to find the file if the path was not specified. so lets
assume we want to search a file that could exist anywhere either in c
drive or g drive. could even be in sub folders. the script should find
this file and ask before deleting.


set "file=\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr
\testing.txt"
set "answer="
if exist "%file%" (
echo found the file on server servernameA
echo found the file on server servernameA >>"file.log"
set /p "answer=Delete the file? [y/N] :"
)
if /i "%answer%"=="y" del "%file%"

IP logged
wbrost
Intermediate



Thanked: 11
Posts: 215




« Reply #14 on: December 03, 2009, 07:48:31 AM »

A functionality to find the file if the path was not specified. so lets
assume we want to search a file that could exist anywhere either in c
drive or g drive. could even be in sub folders. the script should find
this file and ask before deleting.

this is what the batch I provided does. you would need to map a network drive to the server's C or G then CD to the mapped drive. The batch will scan every folder and list the files found in each directory. If you want to change this behavior modify the last part of the batch (ECHO %FILE%) to the commands you wish to run. Let me know if you need help modifying the code.
IP logged
Pages: [1] 2  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Search Files on multiple servers « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.167 seconds with 20 queries.