#!/bin/bash
export SDP_INSTANCE=${SDP_INSTANCE:-Undefined} 
export SDP_INSTANCE=${1:-$SDP_INSTANCE} 
if [[ $SDP_INSTANCE == Undefined ]]; then 
   echo "Instance parameter not supplied." 
   echo "You must supply the Perforce instance as a parameter to this script." 
   exit 1 
fi 

. /p4/common/bin/p4_vars $SDP_INSTANCE

if [[ -f "$P4ROOT/server.pid" ]]; then
  pid=$(cat "$P4ROOT/server.pid")
else
  exit 0
fi

$P4CBIN/p4login
p4 monitor show -ale | grep -v $pid | grep -a IDLE | grep -a -v svc_ | grep -a -v "00:0[0-5]:" | awk '{print $1}' | xargs -n 1 p4 monitor terminate > /dev/null 2>&1
p4 monitor show -ale | grep -v $pid | grep -a IDLE | grep -a -v svc_ | grep -a -v "00:0[0-6]:" | awk '{print $1}' | xargs -n 1 kill > /dev/null 2>&1
p4 monitor show -ale | grep -v $pid | grep -a Init | grep -a -v svc_ | grep -a -v "00:0[0-5]:" | awk '{print $1}' | xargs -n 1 p4 monitor terminate > /dev/null 2>&1
p4 monitor show -ale | grep -v $pid | grep -a Init | grep -a -v svc_ | grep -a -v "00:0[0-6]:" | awk '{print $1}' | xargs -n 1 kill > /dev/null 2>&1
