The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
moving directories to new directories on multiple servers mackdaddy07 Shell Programming and Scripting 0 04-06-2007 08:30 AM
append 3 users in /etc/passwd melanie_pfefer Shell Programming and Scripting 3 03-23-2007 02:36 AM
SQLplus in Shell scripts trupti_d Shell Programming and Scripting 12 03-16-2007 05:46 AM
Scripts for ID´s free in /etc/passwd oscar_acm Shell Programming and Scripting 2 11-15-2005 08:50 PM
sqlplus and sh scripts (to_char command)) josecollantes UNIX for Advanced & Expert Users 4 09-06-2001 06:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2007
Registered User
 

Join Date: Apr 2007
Posts: 15
Stumble this Post!
editing sqlplus id@passwd in multiple scripts, users and directories

hi all,
i was given by my supervisor a task to search for scripts which contain oracle sqlplus i.e "myusername/mypasswd @myDB" in every /home/userfolder, which are, all the scripts made by different user. I've done some find command to search string for sqlplus, but it may up too long to respond. And it was searching, some directories denied the permission to read the files. May be it was the admin folder(right?i new to UNIX). therefore, i try to search some example in this forum but, unlucky to find one similarly. I need help to clear me up:

1) i log on as normal user only, so, it is possible to editing scripts like i mention above? what about that sort of "permission"?should asking for super user id or not?

2) how am i going to seek for oracle sqlplus scripts which have the "myusername/mypasswd @myDB" in every sh scripts,perl etc in every user directories. And if it found it, it is enable to modified?

3) is there any example/testing sed scripts which i seem maybe would help for
the task?

thanks in advance,

regards,
helmi
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-08-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
Quote:
Originally Posted by Helmi
hi all,
i was given by my supervisor a task to search for scripts which contain oracle sqlplus i.e "myusername/mypasswd @myDB" in every /home/userfolder, which are, all the scripts made by different user. I've done some find command to search string for sqlplus, but it may up too long to respond. And it was searching, some directories denied the permission to read the files. May be it was the admin folder(right?i new to UNIX). therefore, i try to search some example in this forum but, unlucky to find one similarly. I need help to clear me up:
use find with xargs
find . -name '*.*' -print | xargs grep -il 'searchpattern'

if enough permission is not available then use the following form

find . -name '*.*' -print 2>/dev/null | xargs grep -il 'searchpattern'

Quote:
1) i log on as normal user only, so, it is possible to editing scripts like i mention above? what about that sort of "permission"?should asking for super user id or not?
write permission should be available to edit the scripts
root permission is not required as such, it is enough if you have the perms of the owner or write perm to the group atleast


Quote:
2) how am i going to seek for oracle sqlplus scripts which have the "myusername/mypasswd @myDB" in every sh scripts,perl etc in every user directories. And if it found it, it is enable to modified?

3) is there any example/testing sed scripts which i seem maybe would help for
the task?
Sorry am not clear with this !
Reply With Quote
  #3 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: May 2007
Posts: 8
Stumble this Post!
for "search pattern" you can use:

grep -i "sqlplus.*\@"

This will find all occurrences of sqlplus, followed by any number of characters, followed by the @ sign. The backslash "\" escapes the @ sign so as not to be interpreted by the shell.
Reply With Quote
  #4 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: May 2007
Posts: 27
Stumble this Post!
i think most unix operating systems support the following

find . -type f -exec grep -l sqlplus.*\@ {} \;

find from the current directory down, all files - execute the command 'grep -l sqlplus.*\@' on each of the files

grep -l sqlplus.*\@ displays each file name that contains sqlplus followed by any character up to the '@' sign

Last edited by TinWalrus; 05-08-2007 at 06:28 PM.
Reply With Quote
  #5 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: Apr 2007
Posts: 15
Stumble this Post!
Thanks for the replies.
Quote:
2) how am i going to seek for oracle sqlplus scripts which have the "myusername/mypasswd @myDB" in every sh scripts,perl etc in every user directories. And if it found it, it is enable to modified?

3) is there any example/testing sed scripts which i seem maybe would help for
the task?
matrixmadhan , supposed that, i found all the script using what you guys have told me, if there any help on how to edit the pattern that i found and apply it all to scripts e.g:
Code:
find . -name '*.*' -print | xargs grep -il 'searchpattern' | sed 's/oldsearchpattern/newsearchpattern/g' (i don't know if this is the correct term of using sed!)
to make it clear:
Code:
in /home/user/

a.sh
b.sh
c.sh
i found above 3 shell script contained the "user/passwd @DB", then
is there any example shell script/sed scripts that could alter or modified all three scripts where i just input the new "user/passwd @DB" when i running the example script.

sorry for much of request,

Regards,
Helmi
Reply With Quote
  #6 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: May 2007
Posts: 27
Stumble this Post!
you could do something like the following...

Code:
#!/bin/ksh
for file in $(find . -type f -exec grep -l sqlplus.*\@ {} \;); do
        echo ${file}
        sed -e 's%sqlplus user/pword@sid%sqlplus newuser/newpword@newsid%g' < ${file} > ${file}.$$
        mv ${file}.$$ ${file}
done
replace user, pword, sid with the current
replace newuser, newpword,newsid with replacement


run from parent directory, you should back up everything first

Last edited by TinWalrus; 05-08-2007 at 07:50 PM.
Reply With Quote
  #7 (permalink)  
Old 05-08-2007
Registered User
 

Join Date: Apr 2007
Posts: 15
Stumble this Post!
thanks all!
i try to think that if the script to edit the sqlplus is running, it will also edit the all the variables that set in that editing scripts. Hence, if being executed for the second time, nothing will changed, right?

using:
Code:
find . -type f -exec grep -l sqlplus.*\@ {} \;
will result:
Code:
./sql
./editor.sh
where editor.sh contained those variable of sqlplus. how to avoid this editor.sh also being edited? But, anyway, it is okay since i have to run this jus t once. Thanks again

Regards,
Helmi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0