username passwd expect

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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;

Re: username passwd expect

onlineviewer schreef:

Quoted text here. Click to load it

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.

  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" ;

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

Affijn, Ruud

"Gewoon is een tijger."

Site Timeline