username passwd expect
am 14.09.2006 06:36:03 von lancerset
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]");
}
Re: username passwd expect
am 14.09.2006 10:07:28 von rvtol+news
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 ()
{
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."