We usually face situation where we need to encrypt password for shell scripts . Recently we faced this requirement and below is how we added encrypted password in shell script
We need to retain file containing hexadecimal value . in our case it was /dbmonitoring/clone/clone.conf
################ Encrypt Phase #################
cat /tmp/pass.lst
Pass#Fri_09_24_2021
echo ${pass} > /tmp/pass.lst
hex=`perl -e 'print unpack "H*",\`cat /tmp/pass.lst\`'`
echo $hex
50617373234672695f30395f32345f323032315f74617267657a
echo $hex > /dbmonitoring/clone/clone.conf
cat /dbmonitoring/clone/clone.conf
50617373234672695f30395f32345f323032315f74617267657a
################ Decrypt Phase #################
decrypt=`perl -e 'print pack "H*",\`cat /dbmonitoring/clone/clone.conf\`'`
echo $decrypt
Pass#Fri_09_24_2021 ▒
Password=${decrypt:0:-2}
echo $Password
Pass#Fri_09_24_2021
sqlplus sys/${Password}@CLONE1 as sysdba
No comments:
Post a Comment