walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use FindBin qw ($Bin); use lib "$Bin/lib"; use General; use MkPasswd; use Functions; use POSIX ":sys_wait_h"; $|++; $Expect::Log_Stdout=0; #$Expect::Debug=2; #$Expect::Exp_Internal=1; open SERVER_LIST,"<$ARGV[0]" or die $!; my @hosts = <SERVER_LIST>; close SERVER_LIST; my (@pids, $count); print "Please enter the username: "; chomp(my $user = <STDIN>); getPassword("Please enter your password: "); for my $host(@hosts) { chomp $host; $count++; my $pid = fork(); push @pids , $pid; die "Fork failed\n" unless defined $pid; next if $pid; # get parent to reiterate and fork more kids my $login = getPrompt($host); die "Login failed\n" unless $login eq "success"; my $password = mkpasswd(-length => 8, -minnum => 2, -minlower => 2, + -minupper => 2, -minspecial => 2); my $result = changePasswd($password,$user); print "$host -- $password -- $result \n"; exit; # kill child } # wait for kids to finish, no zombies on us my $kids; do { $kids = waitpid(-1,&WNOHANG); } until $kids == -1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fork Expect SSH Spawn
by Illuminatus (Curate) on Mar 24, 2009 at 22:57 UTC |