Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

Display file content but mask password value in bash

Hi Experts,
As part of my automated verification task using ssh on remote server

1. Would like to (cat) display the content of a property file on the linux server.
2. So we dont login to each target server and check the value.
3. Instead by executing ssh user@server1 "cat /path/to/property/file" would display the content.
4. Since i also have password in the property file...would like to mask it with 'xxxxxxxx' e.g not showing the actual value.

pls help how to show the content of a file but mask only the password value

Sample file content
hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=tiger
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1

Open in new window



Expected output display
hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=xxxxxx
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1

Open in new window

Avatar of arnold
arnold
Flag of United States of America image

Not sure I understand your question. Where are you displaying the script?

Splitting the credential setting from the data accessing would let you display the processing without disclosing the credentials if that is what you are after"
Avatar of enthuguy

ASKER

sorry about that. have updated my question. hope i'm bit clear now.

yes, trying to display the content without password actual value
ssh user@server1 "cat /path/to/property/file"

Open in new window

It does not clarify what the end result you are trying to achieve.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks arnold, that helped me
Hi arnold,
could you pls help me how to mask two properties in single go please

hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=tiger
username_wls=weblogic
password_wls=welcome1
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1
Try echo data from above through the sed below

sed -e 's/(db_password|password_wls)=.*/$1=xxxxxxxx/g'

If it works, use ....
That cat command and pipe is extraneous and redundant, since sed takes the file name as a final argument already.  
ssh user@server1 "sed -e 's/db_password=.*/db_password=xxxxxxxxx/i'  /path/to/property//file"