How to switch user while executing the script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vipinc
    New Member
    • Jul 2007
    • 4

    How to switch user while executing the script

    Hi guys,

    In my script, I need to switch to another user to execute a command which I don't have the privilege to run. Actually the script copies a file from one directory to another. The script running user doesn't have the permission in target directory. So I need to switch to another user for the same. I tried 'su' command in unix.But it failed to accept the password.evenif I echo the password its prompting again for the password when it executes. Is there any way to achieve this functionality?. ... Please help

    Thanks in advance,

    Vipin C
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Unfortunately, there is no way to do this in a Perl script. I know, I had this though quite a while ago when I was working on a script that needed to do stuff as two different users. The only way to do it is to create a script for each user to kick off, to do the tasks they need to.

    Regards,

    Jeff

    Comment

    • vipinc
      New Member
      • Jul 2007
      • 4

      #3
      Thanks Jeff...

      But the issue here is, Iam calling the script from one of my informatica workflows. When informatica executes the script it executes as a particular user which we can't change. That why we thought of switch user in the script method....Can you put some light on this issue..

      Thanks in advance

      Vipin C

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Unfortunately, I know nothing about Informatica or its workflows, so I cannot even begin to comment on that. What I do know is that if you need some tasks done by a script, those tasks will be completed by the user account that kicks off the script. I am not sure how you are going to solve your problem, especially in an automated fashion as it looks like you are trying to do it.

        Regards,

        Jeff

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          Originally posted by vipinc
          Hi guys,

          In my script, I need to switch to another user to execute a command which I don't have the privilege to run. Actually the script copies a file from one directory to another. The script running user doesn't have the permission in target directory. So I need to switch to another user for the same. I tried 'su' command in unix.But it failed to accept the password.evenif I echo the password its prompting again for the password when it executes. Is there any way to achieve this functionality?. ... Please help

          Thanks in advance,

          Vipin C
          Best solution: Simply update the permissions of the directory the script needs access to.

          Perlish Solution: Whenever you need to interact with the system in more than a single command type way, use the Expect module.

          cpan Expect

          It will let you type a password exactly when the su command prompts for it.

          - Miller

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            How will the Expect module be effected if he cannot change the directories permissions? For what I was working on when I had this issue, the directories permissions could not be modified as they were needed the way they were ( for security reasons).

            The only thing I can think of in that situation is maybe getting yourself added to the group that has rights to execute in those directories, if possible.

            Regards,

            Jeff

            Comment

            • miller
              Recognized Expert Top Contributor
              • Oct 2006
              • 1086

              #7
              The Expect module lets you automate anything that you would normally do from the command prompt. Basically it lets you interact with the system in any situation where it "expects" a human. Such as a prompt for a password.

              The module itself advocates against such usage, as it's unsecure. However, it suggest alternatives, such as using "sudo" instead of "su". Which is better security practice anyway.

              - Miller

              Comment

              • vipinc
                New Member
                • Jul 2007
                • 4

                #8
                Thanks Miller and Jeff.......

                I have tried those options too....but since its a secure server, they won't allow adding the user to a group which have the permissions. Also sudo won't work since that utility or module is not available in the server..I don't know much about the EXPECT module in Perl....Miller, How can I check whether this EXPECT module is available in the server?.....It would be a great help in that case.

                Thanks in advance,

                Vipin

                Comment

                • miller
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1086

                  #9
                  perldoc perlfaq3 How do I find which modules are installed on my system?

                  - Miller

                  Comment

                  • vipinc
                    New Member
                    • Jul 2007
                    • 4

                    #10
                    Again failure...it seems EXPECT module is not installed in the machine...and they are not ready to install it because of security reasons..

                    Miller / Jeff,..Whats next???? :-(

                    Thanks,

                    Vipin C

                    Comment

                    • numberwhun
                      Recognized Expert Moderator Specialist
                      • May 2007
                      • 3467

                      #11
                      Originally posted by vipinc
                      Again failure...it seems EXPECT module is not installed in the machine...and they are not ready to install it because of security reasons..

                      Miller / Jeff,..Whats next???? :-(
                      Unfortunately, dealing with situations like this is never easy. It looks to me like you are going to have a fight on your hands to either get the needed module(s) installed or get permissions changed, just so you can do what you need to do.

                      With projects of this nature, dealing with things that "HAVE" to get done and in a secure environment, sometimes you end up reaching that brick wall that both parties are pushing on. On one side is the developer saying "I need this to do my job" and on the other is the business saying "Get this done and working now!". You almost have to take center stage and make sure everyone knows that THIS is where you stand in your project and either one of THESE two things happens or the project will not be able to be completed. Heck, even throw out the idea that the "deadline will not be met". That is always a good one.

                      Either way, I wish you luck. If it turns out that they give you either or and you need additional help, be sure to let us know and we will do what we can.

                      Regards,

                      Jeff

                      Comment

                      Working...