#!/usr/bin/perl # CS357 ASSIGNMENT 3 # Information analyzer for syscheck.pl # Dan J. Fraser (1219229) # for each file on the command line, do... foreach $file (@ARGV) { #open the file for reading... open(MACHINE,$file) or die "couldn't open machine file: $!\n"; $samples = $downtime = 0; # reset our counters while () { # loop through each line of the input file chomp; # chop off the \n ($time,$stat) = split(' '); # split it into time/status $samples++; # count the line if ($stat eq "down") { # if it is down, count the number of times it was down. $downtime++; } } # figure out the percentage of downtime to samples. $downpercent = $downtime/$samples * 100; # print the percentage if there was some downtime. print "$file downtime: ".$downpercent."%\n" if ($downpercent); }