Subject: sun 4.1.2 kill dup pine process script

From: Muriel McKay <[email-masked]>
Date: Wed, 6 Oct 1993 10:49:25 -0400 (EDT)

Following is script for SUN os 4.1.2 (this one was a collaboration between
John Benjamins and Dave Chajdiak )which will check for existing pine
process and kill it on request . Hope this helps . 

Muriel McKay ,
Analyst , Dsktop Computing Support 
Computing and Information Services,
ABB 132 . Ext. 23630 . McMaster University , Hamilton , Ontario, Canada
--------------------------------------------------------------------------

#!/usr/local/bin/perl -P-   # -*-Perl-*-

# Set up variables

$Answer = not;
$Continue = not;
$Kill = no;
$User = $ENV{'USER'} || $ENV{'LOGNAME'} || (getpwuid($<))[0];
$LockFile = "/tmp/\.\\usr\\spool\\mail\\".$User;
$RealPine = "/usr/local/pine/bin/pine.exe";

open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!";
open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!";
select(TTYOUT);
$| = 1;
select(STDOUT);

# Handle signals

$SIG{'INT'} = 'IGNORE';
$SIG{'TERM'} = 'IGNORE';
$SIG{'TSTP'} = 'IGNORE';
$SIG{'HUP'} = 'cleanup';

sub ignore {
    print "\nUnknown command\n\n";
}

sub cleanup {
	system "stty -cbreak echo </dev/tty >/dev/tty 2>&1";
}

#

system "stty cbreak -echo </dev/tty >/dev/tty 2>&1";

# Look for the pine lock file in /tmp

if ( -f "$LockFile" ) {
    while ( $Answer eq 'not' ) {
        print TTYOUT "\
You have another copy of pine running.  This may be the result of rebooting \
your PC while you were logged in to offsv1.  In any case, do you want to kill \
the other session and start a new one? [y/n]: ";
        read(TTYIN, $Answer, 1);
        if ($Answer =~ /^y/i) { 
            print TTYOUT "\n";
            $Kill="yes"; 
	}
        elsif ($Answer =~ /^n/i) {
            while ($Continue eq 'not') {
                print "\n\
******** WARNING ******** WARNING ******** WARNING ******** WARNING ********\
\
Pine will now start in READ ONLY mode.  This means you will not be able to
change your inbox folder.  Are you sure you want to do this? [y/n]: ";
		read(TTYIN, $Continue, 1);
		print TTYOUT "\n";
                if ($Continue =~ /^y/i) {
                    &cleanup;
		    exec $RealPine, @ARGV;
		    die "Can't run $RealPine: $!";
		}
                elsif ($Continue =~ /^n/i) {
		    &cleanup ; exit;
		}
                elsif ($Continue =~ /^q/i) {
		    &cleanup ; exit;
		}
		else {
		    print TTYOUT "\nPlease answer with y or n only please\n";
                    $Continue="not";
		}
	    }
	}
	elsif ($Answer =~ /^q/i) {
	    &cleanup ; print "\n" ; exit;
	}
	else {
            print TTYOUT "\n\nPlease answer with y or n only please\n\n";
            $Answer="not";
	}
    }
}

# Kill the old one?

if ( $Kill eq "yes" ) {
    system "/usr/kvm/fuser -k $RealPine >/dev/null 2>&1";
}

&cleanup;

# If we get here, we want to start the real Pine executable

exec $RealPine, @ARGV;
die "Can't run $RealPine: $!";

---

From: Matt Simmons <[email-masked]>
Date: Wed, 6 Oct 1993 10:40:10 -0500 (CDT)

> ABB 132 . Ext. 23630 . McMaster University , Hamilton , Ontario, Canada
This is a wonderful, great script, there's only one slight problem... It 
doesn't kill the old pine process....