[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1011
  • Last Modified:

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
1
steelpulse
Asked:
steelpulse
  • 7
  • 5
1 Solution
 
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
 
steelpulseAuthor Commented:
Where do I tell it to pick up the new file?  It is saying system cannot find the file specified.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now