Link to home
Start Free TrialLog in
Avatar of steelpulse
steelpulse

asked on

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
Avatar of JBart_17
JBart_17
Flag of United States of America image


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

 
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steelpulse
steelpulse

ASKER

Where do I tell it to pick up the new file?  It is saying system cannot find the file specified.
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
All i get now is a black screen.
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.
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
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?
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.
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

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
Wow, nothing for all that work?

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



[Admin Edit - http:#a22878014]