#!/usr/bin/perl -W use scr_rsh; my @properties = ("run","conf"); my $cmd_run = "ps -ef|grep newmatch | grep \" 1 \"|wc -l"; my $cmd_conf = "wc -l /usr/local/multiplex.conf"; my ($pid,@pid); my $passwd = ask; print "\n"; # hash of hashes our $domatch = {}; # Hash of Hashes # set default values of HoH for(my $key1 = 0; $key1 <= $#ARGV; $key1++) { foreach my $key2 (@properties) { my $domatch = { $ARGV[$key1 ] => {$key2=>'0'} }; } } # Fork processes for($key1=0, $i = 1; ($i <= 2) && ($key1 <= $#ARGV); $i++,$key1++) { $pid=fork(); push @pids, $pid; if($pid == 0) { #Child Process $domatch->{$ARGV[$key1]}->{"conf"} = &get_proc_run($p +asswd,$ARGV[$key1]); $domatch->{$ARGV[$key1]}->{"run"} = &get_proc_conf($p +asswd,$ARGV[$key1]); &prt_result($ARGV[$key1]); exit(0); } if("$i" == "2") { $i=0; } } foreach my $childpid (@pids) { waitpid($childpid,0); } #-------------------------------------------- # Beging Sub-Routines #-------------------------------------------- sub prt_result { my $host = shift; if( $domatch->{$host}->{run} eq $domatch->{$host}->{conf} ) { print "$host green: $domatch->{ $host }->{conf}/$domat +ch->{ $host }->{run}\n"; } else { print "$host red: $domatch->{ $host }->{conf}/$domatch +->{ $host }->{run}\n"; } } sub get_proc_conf { my $passwd = shift; my $host = shift; # Get number of newmatch configured to be run on each server my $line = scr_remote("$passwd", "$cmd_conf", "$host"); chomp($line); my($junk,$wc) = split(/\s+/,$line); $wc =~ s/\s//g; # string spaces in a string #$domatch->{$host}->{"conf"} = "$wc"; return $wc; }sub get_proc_run { my $passwd = shift; my $host = shift; # Get PPID of newmatch only my $line = scr_remote("$passwd", "$cmd_run", "$host"); chomp($line); $line =~ s/\s//g; # string spaces in a string #$domatch->{$host}->{"run"} = "$line"; return $line; }
Edit kudra, 2001-11-23 Added additional desc to title
In reply to forking: retaining variables after the child exits by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |