#!/usr/bin/perl #=============================================================================== # # checkout # $Id: checkout,v 1.1.1.1 2008-10-21 16:18:33 ebastos Exp $ # # Usage: checkout [-v|-h] # # AUTHOR: Eri Ramos Bastos # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # #=============================================================================== my $config_file="/etc/checks.txt"; #=============================================================================== # No need to change from this point #=============================================================================== use strict; use warnings; use Getopt::Std; #=============================================================================== # Initializing variables #=============================================================================== my $PS; my @processesOK=(); my %seen = (); my $CurrentProcess; my $VERBOSE; #=============================================================================== # Parsing command line arguments #=============================================================================== foreach (@ARGV) { if (/-v(erbose)?$/) {$VERBOSE=1} elsif (/-h(elp)?$/) {print "Usage: checkout [-v|-h] \n"; exit 0} else {die("Unknown option $_ . \nUsage: checkout [-v] \n")} } #=============================================================================== # ps takes different arguments depending on the operating system #=============================================================================== my $OperatingSystem=`uname`; if ($OperatingSystem =~ /Linux/) { $PS="ps auxwww"; } elsif ($OperatingSystem =~ /SunOS/){ $PS="ps -efl"; } else {die("Don't know parameters for $OperatingSystem. Aborting.\n")} #=============================================================================== # Load processes from configuration file #=============================================================================== open(FILE, $config_file) or die("Unable to open file"); my @processes = ; close(FILE); #=============================================================================== # Check which processes are running and avoids duplicates #=============================================================================== foreach $CurrentProcess (`$PS`){ foreach (@processes){ chomp; if ($CurrentProcess =~ $_){ push(@processesOK,, $_) unless $seen{$_}++; } } } #=============================================================================== # Verbose mode will also display process that are OK #=============================================================================== if ($VERBOSE){ foreach (@processesOK){ print "[checkout] $_ is running - OK\n"; } } #=============================================================================== # Displays all missing processes #=============================================================================== foreach my $item (@processes) { unless ($seen{$item}) { print "[checkout] $item is NOT running - FAILED\n"; } } exit 0;