open(HOST,"<$ARGV[0]");
my $i++;
my $msu_total=0;
my $total=0;
my %total;
my %done;
while(my $line=<HOST>) {
    if ($line=~/^\#/) { next; }
    my ($domain,$host)=(split(':',$line))[1,3];
    chomp($host);
    if (!$host || exists($done{$host})) { next; }
    $done{$host}=1;
    print($host." -> ");
    my $result=`curl --user lonadm:litelite -m 5 -s http://$host/cgi-bin/userstatus.pl?simple`;
    my ($count)= ($result=~/\&Active=(\d+)\&/);
    print($count."\n");
    $total+=$count;
    if ($domain eq 'msu') { $msu_total+=$count; }
    $total{$domain}+=$count;
#    if ($i++==14) { last; }
}

print("\n Total\t= $total\n");
print("\n MSU Total\t= $msu_total\n");
open(LOG,">>$ARGV[1]");
print LOG (time." $total ");
print(time." $total ");
foreach my $domain (sort(keys(%total))) {
	print LOG ("$domain $total{$domain} ");
	print ("$domain $total{$domain} \n");
}
print LOG ("\n");
print("\n");
close(LOG);
