Click here to get back home

username passwd expect

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
username passwd expect onlineviewer 09-14-2006
Posted by onlineviewer on September 14, 2006, 12:36 am
Please log in for more thread options


Hello All,

I have an array where @array[0] contains all the usernames and
@array[1] contains the corresponding passwds. I am trying to use the
expect module to send the passwd when prompted for passwd. I have the
following so far, but i'm not sure if i am approaching this the right
way. And the syntax for the expect object doesnt seem to be right
either. Any suggestions? Thanks

use strict;
use Expect;

foreach my $val($values[0]){
system `useradd $val`;
system `passwd $val`;
my $exp = new Expect;
$exp->send("$values[1]");
$exp->send("$values[1]");
}


Posted by Dr.Ruud on September 14, 2006, 4:07 am
Please log in for more thread options


onlineviewer schreef:

> I have an array where @array[0] contains all the usernames and
> @array[1] contains the corresponding passwds. I am trying to use the
> expect module to send the passwd when prompted for passwd. I have the
> following so far, but i'm not sure if i am approaching this the right
> way. And the syntax for the expect object doesnt seem to be right
> either. Any suggestions? Thanks
>
> use strict;
> use Expect;
>
> foreach my $val($values[0]){
> system `useradd $val`;
> system `passwd $val`;
> my $exp = new Expect;
> $exp->send("$values[1]");
> $exp->send("$values[1]");
> }

Your question is more about how to use a multidimensional array (see
perldsc) than about Expect, so I am transfering this to clpm.

1. You are talking about @array[0], but in your code I see $values[0].
2. A hash might be more convenient (unless the storage order in the
array matters).
3. Show how you put data in your array.
4. See `perldoc -q quot` about when and why "$vars" is bad.


#!/usr/bin/perl
use warnings ;
use strict ;
use Data::Dumper ;

my @user_pass ;

while (<DATA>)
{
push @user_pass, [ /\S+/g ] ;
}
print Dumper(\@user_pass), "\n" ;

for my $row (@user_pass)
{
print $row->[0], ":\t", $row->[1], "\n" ;
}

__DATA__
john f5q*d&7d
sue Gy^u&%x8


--
Affijn, Ruud

"Gewoon is een tijger."



Similar ThreadsPosted
Expect - "sleep" executed at the wrong time (before an expect(... send...) instead of after) September 18, 2008, 4:58 am
Net::SSH:Perl on Solaris and passwd September 28, 2004, 11:24 pm
Determine NT domain username of web client February 3, 2005, 4:24 pm
Passing username and password using LWP::UserAgent December 11, 2006, 4:40 am
Looking for module that will expands domain/username to email address October 23, 2004, 12:56 am
Net::SSH::Perl dies during logon only when username is entered in stdin November 5, 2004, 3:37 pm
DBI does not do what I expect... March 12, 2008, 4:18 am
using Net::SSH::Perl with Expect November 21, 2005, 3:41 pm
Expect::Simple December 1, 2005, 4:19 pm
Expect::Simple December 2, 2005, 9:22 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap