#!/usr/bin/perl
use strict;
use warnings;

my $numberOfNodes = shift;
if (!defined($numberOfNodes)) {
	print "Tell me the number of nodes to generate \n";
	exit(0);
}

open(NODES, "nodes.lst") or die("Cannot open nodes.lst");
my $machines = `cat nodes.lst | wc -l`;
chomp($machines);
my $nodespermach = int ($numberOfNodes/$machines);
my $i = 0;
my $node;
while (<NODES>)
{
	$node = $_;
	chomp($node);

	if ($i == $machines-1) {last; }
    system("./sha1_keygen $nodespermach $node");
	$i++;
}

if ($i * $nodespermach != $numberOfNodes)
{
	my $leftover = $numberOfNodes - $i * $nodespermach;
	system("./sha1_keygen $leftover $node");
}
