It is not a single command that I am supposed to run. I have to change to a different user and run a couple of commands.
But as per your solution, I would be running one specific command. Also where am I passing the password in the sudo command? Password will be figured on the fly so I can't store it in a file. Thanks & Regards, Lakshmi 952-833-1220 -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Tom Phoenix Sent: Friday, July 06, 2007 2:29 PM To: [EMAIL PROTECTED] Cc: beginners@perl.org Subject: Re: su and password in a Perl script On 7/6/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote: > my $pid = open3($wr, $rd, $er, 'sudo -S su - username'); No, you're still using su for what sudo is doing. You want to use sudo's -u option to specify the username, maybe like this: my $pid = open3($wr, $rd, $er, "sudo -S -u $username " . 'someCommand -its -options' # command for sudo to run ); Of course, someCommand needs to be whatever you're really trying to do. In the end, the fourth argument to open3 is a single command line, much as if it were typed into the shell. It goes to sudo, which should read the password from its STDIN and (if all is well) launch someCommand as user $username. If you need to quote any arguments to someCommand, things get lots trickier; but that's sudo. Another word of caution: Since you're not really logged in as the other user, other things (like your current directory, environment variables, favorite shell shortcuts) won't be set up as that user might expect. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/