I need a vbscript or .bat file that will search computers for a file called "tnsnames.ora" and tell me what path it is located in.

need a vbscript or .bat file that will search computers for a file called "tnsnames.ora" and tell me what path it is located in.  I then need a script that will replace the file with an updated file of the same name
steelpulseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JBart_17Commented:

What you need is a script or utility that will do a recursive search and replace.
try this

http://www.softpedia.com/get/System/File-Management/SandR.shtml

 
0
Shift-3Commented:
Paste the script below into a text file with a .cmd extension.  Customize the value of the list variable with the location of a text file which contains the target computer names, one per line.  Customize the value of the newfile variable with the location of the new file to copy.  Running the script will echo commands to replace all instances of the file with the new copy.  

Once you have tested it successfully, remove the ECHO from line 10 to execute the commands.


@echo off
setlocal
 
set list=computerlist.txt
set filename=tsnames.ora
set newfile=c:\files\tsnames.ora
 
for /F %%G in ('type "%list%"') do (
 for /F "tokens=*" %%H in ('dir "\\%%G\c$\%filename%" /A:-D /B /S') do (
  ECHO xcopy "%newfile%" "%%~dpH" /C /H /R /Y
 )
)
 
pause

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
steelpulseAuthor Commented:
Where do I tell it to pick up the new file?  It is saying system cannot find the file specified.
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Shift-3Commented:
Specify the full path of the new file in the newfile variable.  Specify its name (without the drive or folder) in the filename variable.

You may see that message if the file is not located on a machine's C: drive.  To hide it, change line 10 to this:
xcopy "%newfile%" "%%~dpH" /C /H /R /Y > NUL 2>&1
0
steelpulseAuthor Commented:
All i get now is a black screen.
0
Shift-3Commented:
And are the files being copied?

Keep in mind that it will take a long time to run as it is searching the entire C: drive on each machine.
0
steelpulseAuthor Commented:
OK.  It did take awhile and came back with file not found.  Here is what my script looks like:

@echo off
setlocal
 
set list=computerlist.txt
set filename=tsnames.ora
set newfile=c:\files\tsnames.ora
 
for /F %%G in ('type "\\nsdata03\ns_apps\software\tnsnames\computerlist.txt"') do (
 for /F "tokens=*" %%H in ('dir "\\%%G\c$\tnsnames.ora" /A:-D /B /S') do (
  ECHO xcopy "\\nsdata03\ns_apps\software\tnsnames\tnsnames.ora" "%%~dpH" /C /H /R /Y
 )
)
 
pause
0
Shift-3Commented:
The idea with the variables is that you change them once in the set lines and then you don't have to change them in the rest of the code.

At any rate, the way you did it should still work.  Does the file \\nsdata03\ns_apps\software\tnsnames\computerlist.txt contain just the computer names, one per line?  If there are any other characters in it then that could be causing a problem.  

If you take one of the computer names from that file and run dir "\\computername\c$\tnsnames.ora" /A:-D /B /S, do you get any results?
0
steelpulseAuthor Commented:
Thanks.  It is actually working like you stated but I need to add a line that would rename the existing tnsnames.ora to tnsnames.1192008 and copy the new file to that path.  Can that be done.
0
Shift-3Commented:
This should do it.  Remove the ECHOs from lines 11 and 12 to execute the commands.


@echo off
setlocal
 
set list=\\nsdata03\ns_apps\software\tnsnames\computerlist.txt
set filename=tsnames.ora
set newfile=\\nsdata03\ns_apps\software\tnsnames\tnsnames.ora
set newname=tnsnames.1192008
 
for /F %%G in ('type "%list%"') do (
 for /F "tokens=*" %%H in ('dir "\\%%G\c$\%filename%" /A:-D /B /S') do (
  ECHO ren "%%H" "%newname%"
  ECHO xcopy "%newfile%" "%%~dpH" /C /H /R /Y
 )
)
 
pause

Open in new window

0
steelpulseAuthor Commented:
Here is my current script.  It kinda works but the window does not close and it keeps asking for a network path right after it copies the file down.  



@echo off
setlocal
 
net use z: \\crbs5725\ldmain
set list=z:\tnsnamesMI\computerlist.txt
set filename=tnsnames.ora
set newfile=z:\tnsnamesMI\tnsnames.ora
set newname=tnsnames.111

for /F %%G in ('type "%list%"') do (
 for /F "tokens=*" %%H in ('dir "\\%%G\c$\%filename%" /A:-D /B /S') do (
  ren "%%H" "%newname%"
  xcopy "%newfile%" "%%~dpH" /C /H /R /Y
 )
)
end
net use z: /delete
exit
0
Shift-3Commented:
Wow, nothing for all that work?

My scripts accomplished the stated objectives.  Your requirements were unclear and kept changing.
0
Shift-3Commented:
I recommend accepting http:#22878014, as it satisfied the conditions stated in the original question.



[Admin Edit - http:#a22878014]
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.