1

I'm trying to run bash script - that contains perl code in it - on Python. From some reason - it only execute the bash part and not the perl part.

The Python code that call's the bash Script is this : (2 options)

 bashCommand = "/bin/bash createUser.sh "+  str(self.emptyNameField.text()) +" "+ str(self.emptyPWField.text())+" " + str(self.emptyGroupField.text())
        os.system(bashCommand)

subprocess.call([path+'createUser.sh', str(self.emptyNameField.text()),str(self.emptyPWField.text()),str(self.emptyGroupField.text())])

And the bash script:

#!/bin/bash

USER_NAME="$1"
PASSWORD="$2"
UNIQUE_ID="$3"
sudo dscl . create /Users/$USER_NAME
sudo dscl . create /Users/$USER_NAME UserShell /bin/bash
sudo dscl . create /Users/$USER_NAME RealName "$USER_NAME"
sudo dscl . create /Users/$USER_NAME UniqueID $UNIQUE_ID
sudo dscl . create /Users/$USER_NAME PrimaryGroupID 1000
sudo dscl . create /Users/$USER_NAME NFSHomeDirectory /Local/Users/$USER_NAME
sudo dscl . passwd /Users/$USER_NAME $PASSWORD
export USER_NAME
export PASSWORD
export UNIQUE_ID


script=$(cat <<'EOF'

$file = "UsersList.txt";

open LIST, '>>',$file;
print LIST "$ENV{USER_NAME} @ $ENV{PASSWORD}\n";
close(LIST);
EOF
)
perl -e "$script"


echo "User Name: $USER_NAME , Password: $PASSWORD "

Any help would be much appreciated !!!

3
  • Did you try using the full path of the perl executable? like '/usr/bin/perl -e "$script"' Commented Sep 16, 2015 at 8:08
  • 3
    Rube Goldberg, is that you ?-) Seriously, why don't you add some generated C code and a call to gcc ? Commented Sep 16, 2015 at 10:31
  • I'm sure you could get some obfuscated code generators in there too! Commented Sep 16, 2015 at 12:15

1 Answer 1

2

Well, I can't say about collapsing your shell script into python, but all that perl does is:

echo ${USERNAME} \@ ${PASSWORD} >> UserList.txt

Seems a bit overkill to me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.