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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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.
Keep in mind that it will take a long time to run as it is searching the entire C: drive on each machine.
ASKER
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.o ra
for /F %%G in ('type "\\nsdata03\ns_apps\softwa re\tnsname s\computer list.txt"' ) do (
for /F "tokens=*" %%H in ('dir "\\%%G\c$\tnsnames.ora" /A:-D /B /S') do (
ECHO xcopy "\\nsdata03\ns_apps\softwa re\tnsname s\tnsnames .ora" "%%~dpH" /C /H /R /Y
)
)
pause
@echo off
setlocal
set list=computerlist.txt
set filename=tsnames.ora
set newfile=c:\files\tsnames.o
for /F %%G in ('type "\\nsdata03\ns_apps\softwa
for /F "tokens=*" %%H in ('dir "\\%%G\c$\tnsnames.ora" /A:-D /B /S') do (
ECHO xcopy "\\nsdata03\ns_apps\softwa
)
)
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\softwar e\tnsnames \computerl ist.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$\tnsname s.ora" /A:-D /B /S, do you get any results?
At any rate, the way you did it should still work. Does the file \\nsdata03\ns_apps\softwar
If you take one of the computer names from that file and run dir "\\computername\c$\tnsname
ASKER
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
ASKER
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\compute rlist.txt
set filename=tnsnames.ora
set newfile=z:\tnsnamesMI\tnsn ames.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
@echo off
setlocal
net use z: \\crbs5725\ldmain
set list=z:\tnsnamesMI\compute
set filename=tnsnames.ora
set newfile=z:\tnsnamesMI\tnsn
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.
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]
[Admin Edit - http:#a22878014]
What you need is a script or utility that will do a recursive search and replace.
try this
http://www.softpedia.com/g