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).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.