Thanks for the response Tom!!!

I tried the following but of no success:

#!/usr/bin/perl
use IPC::Open3;

my($wr, $rd, $er);
my $pid = open3($wr, $rd, $er, 'sudo -S su - username');
sleep 1; # let it start and ask for password
print $wr "password\n";  # the password


Please let me know if I am missign something!!!

Thanks & Regards,
Lakshmi
952-833-1220

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of
Tom Phoenix
Sent: Thursday, July 05, 2007 5:54 PM
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: su and password in a Perl script


On 7/5/07, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

> I want to automate the following through Perl:
> su - user
> and provide password
> check if the login is successful or not.

You'll probably have an easier time using sudo, instead of su; it's
made for this sort of thing. See whether yours has the -S command line
option, to get the password from its standard input instead of the
terminal. You could try using IPC::Open3, maybe something like this:

  my($wr, $rd, $er);
  my $pid = open3($wr, $rd, $er, 'sudo -S some command');
  sleep 1; # let it start and ask for password
  print $wr "seCret\n";  # the password

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/


Reply via email to