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

## -_- $Name: CallTrack-1_3b $ % $Id: ctstop,v 1.4 2001/01/02 18:48:42 sietse Exp $

use strict;

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

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

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

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

stop;
