#!/bin/ksh
# Reset Notes
# Version 2
# Author: [email protected]
# Date: 4/7/97
# 
############################################################################################
# Find and kill Lotus Notes Clients and clear IPC's
# Lotus Notes 3.x Client running on SunOS 4.1.3_u1 (Solaris 1.1.1)
# Notes client would hang and crash and would not restart unless 
# all processes are killed message queues, shared memory and semaphores 
# that are cleared for the user.
#
# I supported 20 Lotus Notes users on a SPARC 10 clone (SANAR) using HP X-Terminals Enware.yy
#############################################################################################

# AP Code notes December 2004
# Code structure not perfect, looking back now I should have used procedures for better structure.
# But it did work and I enjoyed getting SED to work.
# It was one of thoes scripts that I used twice a day.
# As I supported 20 Lotus Notes users on a SPARC 10 clone (SANAR) using HP X-Terminals Enware.


# Code  Start
if  [[ $1 = "h" ]]
then
      print " Usage: $0 [-all][users]" >&2
      print "   no args delete current users Notes  client and IPC "
      print "   -all    deletes all Notes Clients processes and clears IPC subsystem" >&2
      print "   users   delete all specified users Notes Client and IPC" >&2
      exit 0
fi
#
# If run without options
# then take users name for searches 
#
if [[ $# = 0 ]]
then
     if [ $USER ]       # test to if users login name is available
        then
                print  -n " Delete Notes for $USER ? (y/n) "
                read answer
                if [ $answer = "Y" -o $answer = "y" ]
                then
            # get a list of PID's for the users notes clients
                    N_PID=`ps -ef | grep $USER | grep "latest/sunspa" | grep -v grep |  awk ' { print $2 } '`
            # get a list of ID's for the users IPC usages 
                    IPC_ID=`ipcs | grep $USER | sed '/0x/!d' | awk '{print $1,$2}' | sed -e 's/m/-m/g' -e 's/q/-q/g' -e 's/s/-s/g' |awk '{print $1,$2}'`
                    #echo $N_PID
                    #echo $IPC_ID
            # check if N_PID is not null and execute kill statment 
                    [ "$N_PID" ] && { kill -9  $N_PID ; echo " Notes Killed client for user $USER" ; } || { echo "$0: $USER is not running notes"; }
            # check if IPC_ID is not null and execute ipcrm statment 
                    [ "$IPC_ID" ] && { ipcrm $IPC_ID ;echo " Cleared IPC for user $USER " ; } || { echo "$0: $USER has no IPC usage "; }
                    exit 0
                else
                        print "$0: Canceled by user "
                        exit 2
                fi
        else
                echo  "$0: USER variable not set "
                exit 1
      fi
fi

if [[ $1 = "-all" ]]
then
        if  [ -x /usr/bin/id ]
        then
            eval `/usr/bin/id  |  /usr/bin/sed 's/[^a-z0-9=].*//'`
            if [ "${uid:=0}" -ne 0 ]
            then
                echo "$0: Only root can run $0 with -all option"
                exit 3
            fi
        else
             echo "$0: can't check user id."
             exit 3
        fi
        N_PID=`ps -ef| grep "latest/sunspa" | grep -v grep | awk '{print $2}'`
        IPC_ID=`ipcs | sed '/0x/!d' | awk '{print $1,$2}' | sed -e 's/m/-m/g' -e 's/q/-q/g' -e 's/s/-s/g' |awk '{print $1,$2}'`
        #echo $N_PID
        #echo $IPC_ID
        [ "$N_PID" ] && { kill -9  $N_PID ; echo " \n Notes Killed client for  all users " ; } || { echo "$0: Uable to kill all Notes processess" ; }
        [ "$IPC_ID" ] && { ipcrm $IPC_ID ;echo " Cleared IPC for all users  " ; } || { echo "$0: Not all IPC cleared "; }
        exit 0
fi

if  [ -x /usr/bin/id ]
then
    eval `/usr/bin/id  |  /usr/bin/sed 's/[^a-z0-9=].*//'`
           if [ "${uid:=0}" -ne 0 ]
           then
             echo "$0: Only root can run $0 to remove more than 1 user"
             exit 3
           fi
else
     echo "$0: can't check user id."
     exit 3
fi
#
# kill notes and IPC with users listed
#
for i in $*
do
        if  grep "$i" /etc/passwd > /dev/null 2>&1
        then
                echo $i
                N_PID=`ps -ef | grep "$i" | grep "latest/sunspa" | grep -v grep |  awk ' { print $2 } '`
                IPC_ID=`ipcs | grep "$i" | sed '/0x/!d' | awk '{print $1,$2}' | sed -e 's/m/-m/g' -e 's/q/-q/g' -e 's/s/-s/g' |awk '{print $1,$2}'`
                #echo $N_PID
                #echo $IPC_ID
                [ "$N_PID" ] && { kill -9  $N_PID ; echo " Notes Killed client for user $i" ; } || { echo "  $i is not running notes"; }
                [ "$IPC_ID" ] && { ipcrm $IPC_ID ;echo " Cleared IPC for user $i " ; } || { echo " $i has no IPC usage "; }
        else
                        echo "$0: users $i not found in /etc/passwd"
        fi
done
Hosted by www.Geocities.ws

1