Basic Perl Scripting Exercise 9 To be handed in (per email to kathrin@theochem.kth.se): Thursday 8th Nov. In this exercise we will monitor the state of computers in a computer cluster. We have the following data: --------------------------------------------------------------------- enewetak.priv state = free eolie.priv state = offline jobs = 0/9889.omega.biotech.kth.se, 1/10835.omega.biotech.kth.se elba.priv state = offline etorofu.priv state = job-exclusive jobs = 0/15420.omega.biotech.kth.se, 1/8963.omega.biotech.kth.se -------------------------------------------------------------------- The first line gives the computer name, the state it has (free (meaning no jobs are running), job-exclusive (2 jobs are running) or offline (if the machine is in offline state it cannot accept new jobs, but it might still be running old jobs. In that case we refer to the machine as 'blocked'). You are asked to write a script that will take the above as input and return to you the computer names that have a given state. The state you are interested in should be given as keyword to the script. We will use 'free' or 'blocked'. In case no keyword is specified or an unrelated one, the program should either die or return a warning. Here is how it should look if you try to run the script (./ means execute this script): ./exe9.pl Warning: Usage: Pass free or blocked as the argument. # (then script exits) ./exe9.pl free enewetak is free ./exe9.pl blocked eolie is offline but still has jobs 9889, 10835 running. ./exe9.pl smile I have no idea what you want from me. The script itself should use subroutines. Here is a general form of the script: ------------------------------------------------------------------------------ #! /usr/bin/perl die "Usage: Pass free or blocked as the argument.\n" if @ARGV == 0; if($ARGV[0] eq 'free') { # call a subroutine that prints all free machines; } elsif($ARGV[0] eq 'blocked') { # call a subroutine that prints all machines that are offline AND # still runs job(s); } else { die "I have no idea what you want from me.\n"; } ------------------------------------------------------------------------------