develooper Front page | perl.beginners | Postings from May 2003

RE: passing a password

Thread Previous | Thread Next
From:
Jeff Hardy
Date:
May 1, 2003 05:25
Subject:
RE: passing a password
Message ID:
1051791981.3098.137.camel@comp11847.potsdam.edu
Thanks for the help.  Not sure why I did that backwards in the first
place, but even done the right way as you've shown, it does not accept
the password.  However, the Expect module does the trick flawlessly:

------------------
my $queue = $_[0];
my $command = "/usr/sbin/cupsaddsmb -U admin -v $queue";
my $password = "password\n";
my $timeout = 5;

my $addsmb = Expect->spawn("$command") 
	or die "Cannot spawn $command $!\n";

$addsmb->expect($timeout,
	[ qr/SAMBA: /i, sub { my $self = shift;
		$self->send("$password");
                exp_continue_timeout; }]
        );
$addsmb->soft_close();
-------------------

Thanks for the help...I never would have stumbled across Expect.




On Wed, 2003-04-30 at 08:52, Bob Showalter wrote:
> Jeff Hardy wrote:
> > I have a quick question.  I am writing a script that calls a little C
> > program (in this case, the cups utility cupsaddsmb).  I call the
> > program with no problem using a system call like so:
> > 
> > system("/usr/sbin/cupsaddsmb -U admin $queue");
> > 
> > $queue is the printer i want to add.  The problem is that the
> > cupsaddsmb utility prompts for a password.  How can I send that
> > password along to the program?  I tried making my system call with a
> > pipe to an echo password like this: 
> > 
> > system("/usr/sbin/cupsaddsmb -U admin $queue | echo password");
> 
> This is backwards. If cupsaddsmb reads the password from stdin, you can pass
> it as:
> 
>    system("echo password | /usr/sbin/cupsaddsmb -U admin $queue");
> 
> However, it probably reads the password from /dev/tty, so the above
> technique won't work. If cupsaddsmb doesn't support an alternate way of
> providing the password, you need to use something like the Expect module,
> which lets you control the program through a pseudo tty.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About