#64620 - 2002-04-17 04:49 PM
find and replace
|
ehensley
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
|
|
|
|
#64622 - 2002-04-17 05:45 PM
Re: find and replace
|
Kdyer
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
|
|
Top
|
|
|
|
#64623 - 2002-04-17 05:51 PM
Re: find and replace
|
ehensley
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
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?
|
|
Top
|
|
|
|
#64626 - 2002-04-19 12:58 AM
Re: find and replace
|
MCA
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.
|
|
Top
|
|
|
|
#64628 - 2002-04-19 02:40 AM
Re: find and replace
|
MCA
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.
|
|
Top
|
|
|
|
#64629 - 2002-04-19 04:34 AM
Re: find and replace
|
MCA
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
|
|
Top
|
|
|
|
#64630 - 2002-04-19 04:35 AM
Re: find and replace
|
MCA
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.
|
|
Top
|
|
|
|
#64631 - 2002-05-22 07:36 AM
Re: find and replace
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
|
|
Top
|
|
|
|
#64633 - 2002-05-24 06:17 AM
Re: find and replace
|
MCA
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.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1619 anonymous users online.
|
|
|