walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks! I am currently attempting to fork 25 ssh sessions at a time (this is out of 4,000), then each child changes the password for the user on each server. The password for the user on each server is different. I have a sample script below... Everything works if I do it one at a time, but as soon as I try to fork it, the passwords do not match when changing. It sends the password first time, then when it resends to verify the password does not match. Here is the code below:

#!/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;


Please note: I am working within Solaris 8 and Perl 5.005, and this cannot be changed (sadly).

Replies are listed 'Best First'.
Re: Fork Expect SSH Spawn
by Illuminatus (Curate) on Mar 24, 2009 at 22:57 UTC
    Your code does not look complete to me. Your title implies that you are using Net::SSH::Expect, but it is not in your example. I assume it is part of 'Functions', or one of the other modules you are using. Without the details of where and how you are invoking the methods of Net::SSH::Expect, it is hard to diagnose any possible problem.