3 Replies Latest reply on May 2, 2013 3:55 AM by Gurneet Singh Chopra

    Executing a script as another user on AIX Machine

    Gurneet Singh Chopra



      We need to execute the following script as another user "azastmgt" on AIX Server:


      nexec -e su - azastmgt

      mkdir -p ~/.ssh

      cd ~/.ssh

      echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKG1Twel7tA6btP5CRAV5h5v7Z2xoJwvwsOAKqnH5j3fRk+hwj3Adz+w8e5xuDtCPinw92bITav+zouvwukerdt/ezkorqqZPttmh4mfr6a58ArrXCC/7n0VgSR4YvWCtack95Uw+k+/s4B7D71odXEtVoDTWx1nRdB/4EtW0L5bnTnOFtyzwzL2lnnS3AR4hQA3DDdbV3bPOz7XH/qNt9xupH7WQIJY8/ytd1zArc39laULRKK08jniMsWXAS9YkDgzxxigVAhszaiiWNtW4v43xB/9z22RSsVvebzX7a2VDXspgBG0tSXCG7RWyrlQ4h2Wmzh1tDTvHh8Y0syCa1 azastmgt@ukapx096" >> ~/.ssh/authorized_keys

      chmod 600 ~/.ssh/*


      I am able to accomplish this manually through network shell. However, i am unable to do the same from external command in BLPACKAGE as well as from NSH Script job. Deploy jobs goes in hung state and nsh script job fails.


      Any suggestions how to do the same through deploy job (external command) or nsh script job?



        • 1. Re: Executing a script as another user on AIX Machine
          Soundappan Shanmugam

          Have you done the same login into the server via root password on the machine?

          You can try one more for the same..  as below

          Create this as a .sh script and use file deploy job and execute the same in post script.

          It worked for me earlier during some script deployment and execution.

          Please share the output through the methodology which i have suggested 

          • 2. Re: Executing a script as another user on AIX Machine
            Dipak Gaigole

            I think when you do:

            su - azastmgt


            it is waiting for the password to be entered, thus this behavior seems to be a hung behavior.

            I think you are not mapped to "root" user on that target and thus the "su - USER" is prompting you for the password. Are you mapped to "root" on the target? What did rscd.log shows when you run the job?

            • 3. Re: Executing a script as another user on AIX Machine
              Gurneet Singh Chopra

              Yes, the agent is mapped to root and i did checked it via network shell before proceeding with NSH Script job.


              I had to do the slight modification in the script to get it working from NSH Script Job.


              Had to put -c flag, plus the command which we are running should be into ' '


              New syntax looks like below and works for me, thank you for every one's inputs



              nexec -e

              su - azastmgt -c 'mkdir –p ~/.ssh'


              nexec -e

              su - azastmgt -c 'echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKG1Twel7tA6btP5CRAV5h5v7Z2xoJwvwsOAKqnH5j3fRk+hwj3Adz+w8e5xuDtCPinw92bITav+zouvwukerdt/ezkorqqZPttmh4mfr6a58ArrXCC/7n0VgSR4YvWCtack95Uw+k+/s4B7D71odXEtVoDTWx1nRdB/4EtW0L5bnTnOFtyzwzL2lnnS3AR4hQA3DDdbV3bPOz7XH/qNt9xupH7WQIJY8/ytd1zArc39laULRKK08jniMsWXAS9YkDgzxxigVAhszaiiWNtW4v43xB/9z22RSsVvebzX7a2VDXspgBG0tSXCG7RWyrlQ4h2Wmzh1tDTvHh8Y0syCa1 azastmgt@ukapx096 >> ~/.ssh/authorized_keys'


              nexec -e

              su - azastmgt -c 'chmod 600 ~/.ssh/*'