enthuguy
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
Expected output display
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
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
ASKER
sorry about that. have updated my question. hope i'm bit clear now.
yes, trying to display the content without password actual value
yes, trying to display the content without password actual value
ssh user@server1 "cat /path/to/property/file"
It does not clarify what the end result you are trying to achieve.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks arnold, that helped me
ASKER
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/sc ripts
target_db_client_home=/u01 /app/oracl e/db/clien t_1
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
target_db_client_home=/u01
Try echo data from above through the sed below
sed -e 's/(db_password|password_w ls)=.*/$1= xxxxxxxx/g '
If it works, use ....
sed -e 's/(db_password|password_w
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_passw ord=xxxxxx xxx/i' /path/to/property//file"
ssh user@server1 "sed -e 's/db_password=.*/db_passw
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"