Page 1 of 1 1
Topic Options
#64620 - 2002-04-17 04:49 PM find and replace
ehensley Offline
Fresh Scripter

Registered: 2002-01-22
Posts: 10
Loc: Indianapolis
Im trying to find a way to find and replace a file on all the local machines.

Problem is that its for local win9x, nt, and 2k machines. The file can be in multiple locations.

Is there a simple script for performing a search and replace. File is tsnname.ora.

Top
#64621 - 2002-04-17 05:05 PM Re: find and replace
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Is it on C: or could it be on others as well?

How about something like:

SHELL "%COMSPEC% /C dir /b /s C:\tsnname.ora > C:\out.txt"

Then process C:\out.txt
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64622 - 2002-04-17 05:45 PM Re: find and replace
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
ehensley,

If am assuming this right, your clients are needing a new version of the TNSNAMES.ORA due to a server change.. Can you simply copy an updated version to the client?

- Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#64623 - 2002-04-17 05:51 PM Re: find and replace
ehensley Offline
Fresh Scripter

Registered: 2002-01-22
Posts: 10
Loc: Indianapolis
It's do to several server changes and its either going to be thru sneaker net or login scripts. Guess which one I perfer.

The main problem is that there wasn't a consistent install of the oracle client. SO it could be in several places. And we do need to push the updated file out to the clients.

Top
#64624 - 2002-04-17 06:46 PM Re: find and replace
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Doesn't TNSNAMES.ora have to be in the path or in %ORACLE_HOME%? Could you used these values to locate the one or two directories where you should look?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#64625 - 2002-04-17 07:16 PM Re: find and replace
NTDOC Administrator Online   content
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
ehensley is correct, except for the spelling of the file name. The file TNSNAMES.ORA can be in multiple locations and does not have to be in a specific path that is known by the Registry. It does depend on the file structure where the program was originally installed.

We had this problem a couple years ago. What we did was to make an installer that would search about 5 known install locations and replace any and all of the known file locations.

I would not recommend searching the entire drive and doing replacement as it will take a VERY long time to search complete hard drives. I would do a little research as to the most common install locations in the past and then look for the file in those specific areas and update it as needed.

What about the LISTENER.ORA and SQLNET.ORA files? They may also need to be updated.

Top
#64626 - 2002-04-19 12:58 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We have modify our searchfiles.kix a little bit. We have modify it
in such a way that we will search for all TNSNAMES.ORA files on your C:\
drive.
After finding such files it will replace them with the specified file
as variable $source. In our example we are using:
$source="\\server\netlogon\tnsnames.ora"
which was marked woth "<+++++" notation.
To make this script effective change
$execute_mode="no"
to
$execute_mode="yes"

Our version:
code:
;
; NT/95 search for specified file(mask)s - Kixtart 3.63, 4.x
;
; (c) scripting@wanadoo.nl 2002
;
; vs 1.00 - program (original: searchfiles.kix)
;
$prgrm_version="1.00"
;
$tmp_directory=ExpandEnvironmentVars("%tmp%")
IF (substr($tmp_directory,len($tmp_directory),1) <> "\")
$tmp_directory=$tmp_directory+"\"
ENDIF

; ---------------------------------------------------------------------------
; user definable part
; ---------------------------------------------------------------------------

$debug_mode="no" ; - yes/no - no = no user output will be viewed
$debug_file=$tmp_directory+"kix-info.log"
$execute_mode="no" ; - yes/no - yes= execute COPY command.

$number_of_dirs=1 ; <- increase value by new dirs to look in
DIM $dirs[$number_of_dirs+1]
$dirs[1]="c:\"

$number_of_files=1 ; <- increase value by new files to check for
DIM $files[$number_of_files+1]
$files[1]="tnsnames.ora"

$source="\\server\netlogon\tnsnames.ora" ; <+++++

; ---------------------------------------------------------------------------
;
; ---------------------------------------------------------------------------

$tmp_file=$tmp_directory+"kixtart.tmp"
;
IF (Exist($debug_file) = 1)
del $debug_file
ENDIF
IF ($debug_mode = "yes")
IF (RedirectOutput($debug_file) <> 0)
ENDIF
ENDIF
? "KIX-SearchFiles "+@kix+" (vs "+$prgrm_version+")"+" "+@date+" "+@time
?

IF (Exist($tmp_file) = 1)
del $tmp_file
ENDIF
$eof="~~~ The command completed succesfully ~~~"
;
$i=1
WHILE ($i <= $number_of_dirs)
$k=1
IF (Substr($dirs[$i],len($dirs[$i]),1) <> "\")
$dirs[$i]=$dirs[$i]+"\"
ENDIF
IF ($debug_mode = "yes")
? "check directory: "+$dirs[$i]
ENDIF
WHILE ($k <= $number_of_files)
$entry=$dirs[$i]+$files[$k]
IF (exist($dirs[$i]) = 1)
SHELL "%comspec% /c dir "+CHR(34)+$entry+CHR(34)+" /a /b /o:n /s >>"+$tmp_file
ENDIF
$k=$k+1
LOOP
$i=$i+1
LOOP
SHELL "%comspec% /c echo "+$eof+">>"+$tmp_file
? "check files: "+$files[1]
$i=2
WHILE ($i <= $number_of_files)
? " "+$files[$i]
$i=$i+1
LOOP
?
$count=0
IF (Exist($tmp_file) = 1)
IF (Open(1,$tmp_file,2) = 0)
$completed="no"
WHILE ($completed <> "yes")
$result=Readline(1)
IF (@error <> 0) or (instr($result,$eof) <> 0)
$completed="yes"
ELSE
IF (exist($result) = 1)
$count=$count+1
GOSUB modify_file_info
ENDIF
ENDIF
LOOP
IF Close(1)
ENDIF
ENDIF
ENDIF
IF (Exist($tmp_file) = 1)
del $tmp_file
ENDIF
?
IF ($count = 0)
? "completed. found no entries."
ELSE
? "completed. found "+$count+" entries."
ENDIF
?
IF (RedirectOutput("") <> 0)
ENDIF
IF ($debug_mode = "yes")
? "Informative SearchFiles: output written to file '"+$debug_file+"'."
ENDIF
EXIT
:modify_file_info
? " replace "+$result
;
IF (Exist($source) = 1)
IF ($execute_mode = "yes")
COPY "$source" "$result" /H
ENDIF
ELSE
? " Warning KIX: file '"+$source+"' not available."
ENDIF
RETURN

An output example is:
code:
KIX-SearchFiles  4.02 (vs 1.00)                             2002/04/18 20:15:55

check directory: c:\
check files: tnsnames.ora

replace C:\oracle\tnsnames.ora
Warning KIX: file '\\server\netlogon\tnsnames.ora' not available.
replace C:\WINDOWS\tnsnames.ora
Warning KIX: file '\\server\netlogon\tnsnames.ora' not available.

completed. found 2 entries.

For more information see the related topic to our script searchfiles.kix.

symbol on our homepage has been linked to this related http://kixtart.org topic.

greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64627 - 2002-04-19 01:19 AM Re: find and replace
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I know nothing about Oracle, but when I look for a default file that could be anywhere I try the registry to see if I can determine the install location. I'd suggest this method to avoid a lengthy harddrive search.
Top
#64628 - 2002-04-19 02:40 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Chris S,

We remember that Oracle stores its link in one of those main INI files. The registry is the right place
for looking.
For the questioner will find with above script all TNSNAMES.ORA files which exists on his C-drive.
We will look for additional information. Possible that ehensley can tell what element he want to
change in this file.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64629 - 2002-04-19 04:34 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

We found an oracle script from the past. It was necessary to upgrade:
- from 16bits to 32bits version.
- related DNS names must be changed. so 16bits and 32bits versions must be replaced.

First we are trying to calculate which version was installed. In our
situation it was a known situation: orawin, orawin95 or orant.

Secondly we calculates which program type was installed: F45RUN.EXE or F45RUN32.EXE

Third we replace only 16bits version when F45RUN.EXE exist or
we replace only 32bits version when F45RUN32.EXE exist.
code:
  IF setconsole("hide")
ENDIF
;
; NT/95 logging - Kixtart 3.62, 3.63
;
; (c) scripting@wanadoo.nl, 2000
;
; 1.00 (20001025) original version
;
$prgrm_version="1.00"
;
IF (@inwin = 1)
$NT_mode="yes"
ELSE
$NT_mode="no"
ENDIF
break off
flushkb

; - :script_oracle_location

$f45run="orawin" ; - bin\f45run.exe -
$f45run_info="NONE"
IF (exist("c:\orawin\bin\f45run.exe") = 1)
$f45run="orawin"
ELSE
IF (exist("c:\orawin95\bin\f45run.exe") = 1)
$f45run="orawin95"
ELSE
IF (exist("c:\orant\bin\f45run.exe") = 1)
$f45run="orant"
ELSE
$f45run="NONE"
ENDIF
ENDIF
ENDIF
;
$f45run32="orawin95" ; - bin\f45run32.exe -
$f45run32_info="NONE"
IF (exist("c:\orawin95\bin\f45run32.exe") = 1)
$f45run32="orawin95"
ELSE
IF (exist("c:\orawin\bin\f45run32.exe") = 1)
$f45run32="orawin"
ELSE
IF (exist("c:\orant\bin\f45run32.exe") = 1)
$f45run32="orant"
ELSE
$f45run32="NONE"
ENDIF
ENDIF
ENDIF

; - :script_oracle_update

$oracle_update="o:\oracle\tnsnames.ora" ; <- new version -
$oracle16="c:\"+$f45run+"\network\admin\tnsnames.ora"
$oracle32="c:\"+$f45run32+"\network\admin\tnsnames.ora"
$oracle_info="ORACLE-UPDATE "

IF (exist($oracle_update) = 1) AND (exist($oracle16) = 1)
IF ($NT_mode = "yes")
shell "%comspec% /e:1024 /c c:\winnt\system32\attrib.exe -r "+$oracle16
ELSE
shell "%comspec% /e:1024 /c c:\windows\command\attrib.exe -r "+$oracle16
ENDIF
copy $oracle_update $oracle16
IF (@error = 0)
ENDIF
$oracle_info=$oracle_info+" "+LCASE($oracle16)
ELSE
$oracle_info=$oracle_info+" "+$f45run+"-SKIP-"
ENDIF
;
IF (exist($oracle_update) = 1) AND (exist($oracle32) = 1)
IF ($NT_mode = "yes")
shell "%comspec% /e:1024 /c c:\winnt\system32\attrib.exe -r "+$oracle32
ELSE
shell "%comspec% /e:1024 /c c:\windows\command\attrib.exe -r "+$oracle32
ENDIF
copy $oracle_update $oracle32
IF (@error = 0)
ENDIF
$oracle_info=$oracle_info+" "+LCASE($oracle32)
ELSE
$oracle_info=$oracle_info+" "+$f45run32+"-SKIP-"
ENDIF

; --------------------------------------------------------------------------

; IF ($debug_mode = "yes")
?
? " F45run "+$f45run
? " F45run32 "+$f45run32
?
? " oracle info "+$oracle_info
?
; ENDIF

:end_script
break on
flushkb

Above code may gives you other ideas.
greetings.

btw: about related INIs see next reaction about WIN.INI and ORACLE.INI
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64630 - 2002-04-19 04:35 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Another part from another script, which we are using also.
  • %windir%\win.ini[oracle]
    ora_config=c:\%windir%\oracle.ini
  • %windir%\oracle.ini
    [oracle]
    local=tns:server_a
Other code for ideas:
code:
; - :script_oracle

IF ($debug_mode = "yes")
?
? "-REGISTRY PART- win.ini + oracle.ini"
?
ENDIF

$execute_mode="yes"
IF ($execute_mode = "yes")
$file_dir="winnt"
SELECT
CASE (exist("c:\windows\win.ini") = 1)
$file_dir="windows"
CASE (exist("c:\winnt\win.ini") = 1)
$file_dir="winnt"
CASE 1
IF ($NT_mode = "yes")
$file_dir="winnt"
ELSE
$file_dir="windows"
ENDIF
ENDSELECT
$filename="c:\"+$file_dir+"\win.ini"
$file_attr=getfileattr($filename)
IF ($debug_mode = "yes")
? " "+$filename+" (attr: "+$file_attr+") -> [oracle] ora_config=c:\"+$file_dir+"\oracle.ini"
ENDIF
IF setfileattr ($filename, 128)
ENDIF
IF writeprofilestring($filename, "oracle", "ora_config", "c:\"+$file_dir+"\oracle.ini")
ENDIF
IF setfileattr ($filename, $file_attr)
ENDIF
;
$file_dir="winnt"
SELECT
CASE (exist("c:\windows\oracle.ini") = 1)
$file_dir="windows"
CASE (exist("c:\winnt\oracle.ini") = 1)
$file_dir="winnt"
CASE 1
IF ($NT_mode = "yes")
$file_dir="winnt"
ELSE
$file_dir="windows"
ENDIF
ENDSELECT
$filename="c:\"+$file_dir+"\oracle.ini"
$file_attr=getfileattr($filename)
IF ($debug_mode = "yes")
? " "+$filename+" (attr: "+$file_attr+") -> [oracle] local=tns:simpln_a"
ENDIF
IF setfileattr ($filename, 128)
ENDIF
IF writeprofilestring($filename, "oracle", "local", "tns:server_a");
ENDIF
IF setfileattr ($filename, $file_attr)
ENDIF
ENDIF

greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64631 - 2002-05-22 07:36 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
solved?
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64632 - 2002-05-24 12:13 AM Re: find and replace
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Why not put the TNSNames.ora in a central place on the network ?? Look at the registry key HKLM\Software\Oracle and the fiels TNS_Admin. This fiels contains directory containing the TNSNames.ora. Furthermore, the TNSNames.ora is the same through different Oracle client versions (16bit, 32bit 7.3.4, 8.0.6, 8.1.7)
_________________________
Kind regards,

Top
#64633 - 2002-05-24 06:17 AM Re: find and replace
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Schuliebug,

FYI

When your clients have a standard structure you suggestion may work,
but mostly people are personalizing their computer. By searching
for the right location by reading related INI and registry keys it is
sure you are changing everything in a correct way.

When those TNSNAMES.ORA file is located on another drives the fast way
may return unexpected results.
Simply a redefined shortcut is enough for big problems. For complex instal-
lation processes we always reinstall configuration files and shortcuts
to prevent such unexpected situation.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.129 seconds in which 0.089 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org