469,362 Members | 2,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

How to switch user while executing the script

4
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
Jul 17 '07 #1
10 5601
numberwhun
3,503 Expert Mod 2GB
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
Jul 17 '07 #2
vipinc
4
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
Jul 17 '07 #3
numberwhun
3,503 Expert Mod 2GB
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
Jul 17 '07 #4
miller
1,089 Expert 1GB
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
Jul 17 '07 #5
numberwhun
3,503 Expert Mod 2GB
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
Jul 17 '07 #6
miller
1,089 Expert 1GB
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
Jul 17 '07 #7
vipinc
4
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
Jul 18 '07 #8
vipinc
4
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
Jul 18 '07 #10
numberwhun
3,503 Expert Mod 2GB
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
Jul 18 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by JaNE | last post: by
6 posts views Thread by Jeff Duffy | last post: by
2 posts views Thread by Oliver | last post: by
2 posts views Thread by Christopher Jedlicka | last post: by
23 posts views Thread by ern | last post: by
19 posts views Thread by rdavis7408 | last post: by
6 posts views Thread by William Pierce | last post: by
1 post views Thread by s99999999s2003 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.