#!/usr/local/sysmansw/runtime/perl/bin/perl -w

#
## -_- $Name: Uptimetrics-1_4b $ % $Id: umstop,v 1.3 2001/01/02 18:49:23 sietse Exp $
#
# ***
# *** Copyright(c) 2000
# ***    Sysman Software B.V. 
# ***
#

use strict;

# Default directory name is ~calltrac - changeable by defining the variable UMDIR
my $UMDIR = $ENV{"UMDIR"};
$UMDIR = $ENV{'HOME'} . "/uptimetrics" if not defined($UMDIR);

sub stop
{
    my ($thissystem, $pid, @pid);

    chomp($thissystem = `uname`);
    if ($thissystem eq "SunOS" || $thissystem eq "HP-UX")
    {
        $pid = `ps -ef|grep $UMDIR/umstart|grep -v grep`;
        if ($pid ne "")
        {
            @pid = split(' ', $pid);
            $pid = $pid[1];
        }
    } elsif ($thissystem eq "Linux")
    {
        $pid = `ps ax|grep $UMDIR/umstart|grep -v grep`;
        if ($pid ne "")
        {
            @pid = split(' ', $pid);
            $pid = $pid[0];
        }
    } else
    {
        print "Uptimetrics not stopped -- this is a unknown system type\n";
        return;
    }

    if ($pid ne "")
    {
        print "Stopping Uptimetrics processes\n";
        kill 15, $pid;
        sleep 2; # let things settle down.
    }
}

stop;
