[K12OSN] Kill User processes on log-off

Andy Rabagliati andyr at wizzy.com
Wed Feb 23 15:53:59 UTC 2005


On Wed, 23 Feb 2005, Jim Christiansen wrote:

> In my 3.x install, all proccesses for a user were killed at both ends.  A 
> script ran at logon that killed all processes and also at logoff.  I wish I 
> could find it.  I don't seem to have a need for it this year.

I squirrelled this one away - is it what you are looking for ?

It runs at login time.

Cheers,      Andy!


#!/bin/sh
#Lumen Software
#www.lumensoftware.com
#collected from various irc chats, and mailing lists

## clean up files left in /tmp ##

# evolution
for evoTmpDir in /tmp/evolution-$EUID-*
do
  [ -d $evoTmpDir ] && rm -Rf $evoTmpDir
done

# orbit & KDE temp directories
[ -d /tmp/orbit-$USER ] && rm -Rf /tmp/orbit-$USER
[ -d /tmp/ksocket-$USER ] && rm -Rf /tmp/ksocket-$USER
[ -d /tmp/kde-$USER ] && rm -Rf /tmp/kde-$USER
[ -d /tmp/mcop-$USER ] && rm -Rf /tmp/mcop-$USER

# remove any scrollkeeper tempfiles
for TempFile in /tmp/scrollkeeper-tempfile*
do
 [ `stat -c %u $TempFile` -eq $EUID ] && rm -Rf $TempFile
done

## session clean up ##

# no touch root, many services will die
[ $USER = 'root' ] && exit 0  

# kill oaf daemon
oafdpids=`ps -u $USER | grep oafd | cut -c1-5`
[ -z $oafdpids ] || kill -1 $oafdpids

# clean up unexpected
LeftoverPids=`ps ho pid -u $USER`
if [ ! -z "$LeftoverPids" ]
then
    logger -it GDM $USER "WARNING processes left behind"
    ps -aef|grep ^$USER | logger -it GDM
    logger -it GDM "TERM signals to $LeftoverPids"
    kill -15 $LeftoverPids | logger -it GDM
    sleep 1
    LeftoverPids=`ps -aef | grep ^$USER | cut -c10-15 `
    if [ ! -z "$LeftoverPids" ]
    then
        logger -it GDM "KILL signals to $LeftoverPids"
        kill -9 $LeftoverPids | logger -it GDM
        sleep 1
        LeftoverPids=`ps -aef | grep ^$USER | cut -c10-15 `
        if [ ! -z "$LeftoverPids" ]
        then
            logger -it GDM "FAIL kill $LeftoverPids"
            ps -aef | grep $LeftoverPids | logger -it GDM
        fi
    fi
fi




More information about the K12OSN mailing list