how to reference bash variables inside perl script inside ba…

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Steven A. DuChene
Date:  
To: plug-discuss
Subject: how to reference bash variables inside perl script inside bash script?
I am attempting to write what I thought would be a simple wrapper
script around ldapmodify that would allow me to easily reset a user's
password. Inside my bash based wrapper script is a single line of perl
that encrypts the password I input and returns it as a specially formatted
string that then gets output to a LDIF file that is eventually sourced by
ldapmodify.

Then I wanted to be able to run the resulting script by doing:

reset_password george newpasswd

to reset the password in ldap to newpasswd for user account george

My problem is I want to be able to pick up $2 from the command line invocation
of my bash script for the desired password and then pass that into the one line
perl piece. But with all of the single quotes, double quotes, back ticks and
etc. I am not able to get the password value in the $2 to be correctly passed
into the perl one line part of the bash script.

The core part of the script I am having a problem with looks like:

#!/bin/bash

OPASS=$2

PASS=`perl -e 'print("userPassword: {CRYPT}".crypt("$OPASS","frat-salt")."\n");'`


The actual value of $PASS is supposed to end up looking like:

userPassword: {CRYPT}frJTbxR6L.kgA

I have looked at doing something like this:

#!/bin/bash

perl << 'EOF'
print("userPassword: {CRYPT}".crypt("$OPASS","frat-salt")."\n");
EOF

but I still don't think the bash variable OPASS would get properly evaluated in the perl invocation.

Any ideas?
--
Steven DuChene


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss