I'm trying to do a basic password encryption script with two parameters but I can't make it work:
#!/usr/bin/bash
set -x
trap read debug
export ppwd=$2;
export usr=$1;
pwd=$(python -c 'import crypt, os,base64; print crypt.crypt("str(os.environ['ppwd'])", "$6$"+base64.b64encode(os.urandom(24))+"$")');
echo $ppwd;
echo $usr:$pwd|chpasswd -ec
I tried using regular bash scripting variables, print os.environ['ppwd'] instead of str(os.environ['ppwd']. The script it's supposed to change the password for AIX environment but it doesn't work. It works if I do it manually using the python command and chpasswd. My guess is that it doesn't pass the variable to the python command.. Debug:
./sc.sh testuser MyPass134
+ trap read debug
++ read
+ export ppwd=MyPass134
+ ppwd=MyPass134
++ read
+ export usr=testuser
+ usr=testuser
++ read
++ python -c 'import crypt, os,base64; print
crypt.crypt("str(os.environ[ppwd]", "$6$"+base64.b64encode(os.urandom(24))+"$")'
+ pwd=bbdf5picgZM4.
++ read
+ echo
++ read
+ echo testuser:bbdf5picgZM4.
++ read
+ chpasswd -ec