How to replace a string to asterisk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace a string to asterisk?
# 1  
Old 04-14-2014
How to replace a string to asterisk?

Hi,

I would like to ask for you idea on how to convert a string to "*". say password and username.

I have a shell script that will promt the user to enter username and password. This will be passed to sqlplus command.

Code:

   echo "Please enter user name"
   read USERNAME

   echo "Please enter password"
   read PASSWORD

   sqlplus -s $USERNAME/$PASSWORD@$HOSTNAME:$PORT/$SERVICE_NAME <<EOF > $OUTFILE
   set verify off
   set serverout on
   set timing on
   set linesize 120

   select supplemental_log_data_min from v\$database;
   exit;

   EOF

the reason for me to do this is for the security purpose, the user does not want the usernames and password to be shown.

Any idea on how to do this?

Thanks
# 2  
Old 04-14-2014
Code:
   echo "Please enter user name"
   stty -echo
   read USERNAME
   stty echo

   echo "Please enter password"
   stty -echo
   read PASSWORD
   stty echo   

   sqlplus -s $USERNAME/$PASSWORD@$HOSTNAME:$PORT/$SERVICE_NAME <<EOF > $OUTFILE
   set verify off
   set serverout on
   set timing on
   set linesize 120

   select supplemental_log_data_min from v\$database;
   exit;

   EOF


Post went all funny for some reason... I think this might do the trick but instead of printing ***'s it will just make it so that the password does not show.

Last edited by pilnet101; 04-14-2014 at 11:04 PM..
# 3  
Old 04-14-2014
Also please note:

Unix ps -ef command will show the sqlplus username and password in plain sight, when you run your script that way.

Any other way will require you securing the shell script, but at least the password will not be visible to the ps command. Passwords in a shell script are a security problem. So, if your script is called foo.sh, be sure it resides in a directory that is owned by the same user as the owner of the foo.sh script.

This also requires that the owner is also the uid that runs the script:

Code:
# protect the script
chmod 700 foo.sh

Code:
 
 # foo.sh
   echo "Please enter user name"
   read USERNAME

   echo "Please enter password"
   read PASSWORD

   sqlplus -s $USERNAME/@$HOSTNAME:$PORT/$SERVICE_NAME <<EOF > $OUTFILE
   $PASSWORD
   set verify off
   set serverout on size 100000
   set timing on
   set linesize 120

   select supplemental_log_data_min from v\$database;
   exit;

Note: SET SERVEROUT ON SIZE nnnnn is only used when you call the dbms_output package in pl/sql. Straight sql does not need set serverout on nnnn. And it is not useful without SIZE nnnnn where n is some large number like 99999.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

2. AIX

Replace string with asterisk(*) in variable

I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using cat $INFILE | while read LINE do stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'` stmt=$stmt' '$stmt1 stmt2=`echo $LINE` STATEMENT=$STATEMENT' '$stmt2 done echo 'Statement with sed -- > '... (5 Replies)
Discussion started by: Vaddadi
5 Replies

3. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies
Login or Register to Ask a Question