Actually I found it on my dev box. The script is very specific to my needs, but 
should give you an idea of how to clean up this kind of junk. True be told I 
tossed it together as a temporary solution until a better method is needed or 
found. I'm positive there are better methods of accomplishing this so feel free 
to provide feedback. Hope it comes in handy.

Cory Oldford

# Make sure hc* logins are legit.
echo "Checking for undead logins"
terminal_users=`who | awk '/hc*/ { if ($2 == $1":0") { print $1 } }'`
for terminal_user in $terminal_users; do
        if ! ping -q -c 1 $terminal_user &>/dev/null; then
                echo "- Found undead login for $terminal_user."
                echo -n "- - Resetting login status"
                if sessreg -d -l $terminal_user:0 -x 
/usr/X11R6/lib/xdm/Xservers $terminal_user &> /dev/null; then
                        echo " OK"
                else
                        echo " FAILED"
                fi
        else
                echo "- No undead logins found."
        fi

done

# Make sure logged out hc* users have no leftover processes or mount points.
echo "Checking for undead processes and mounts"
valid_logins=`who | awk '/hc*/ { print $1 }'`
terminal_users=`ls /home | grep hc`
for terminal_user in $terminal_users; do
        logged_in="false"
        for valid_login in $valid_logins; do
                if [ $valid_login = $terminal_user ]; then
                        logged_in="true"
                fi
        done
        # Kill any undead mounts
        if mount | grep $terminal_user &>/dev/null && [ $logged_in = "false" ]; 
then
                echo "- Found an undead mount used by $terminal_user"
                echo -n "- - Removing mount"
                else
                        echo " FAILED"
                fi
        else
                echo "- No undead mounts found for $terminal_user"
        fi
        if  ps -u $terminal_user &> /dev/null  && [ $logged_in = "false" ]; then
                echo "- Found undead processes running as $terminal_user."
                # Kill whatever processes we can.
                for process in `ps -u $terminal_user | awk '!/PID/ { print $1 
}'`; do
                        echo "- - Killing $process"
                        kill -9 $process 2> /dev/null
                done
                sleep 1 # Give the system a sec to kill the procs
                # If that didn't do the job kill parents of defuncted processes.
                if ps -u $terminal_user &> /dev/null; then
                        for process in `ps -fp $(pgrep -d, -u $terminal_user) | 
awk '!/PID/ { print $3 }'`; do                                echo "- - Killing 
parent $process"
                                kill -9 $process 2> /dev/null
                        done
                fi
                sleep 1 # Give the system a sec to kill the procs
                # Make sure we did what needed to be done.
                if ! ps -u $terminal_user &> /dev/null; then
                        echo "- - All undead processes have been killed for 
user $terminal_user."
                else
                        echo "- - FAILED: Could not kill all undead processes."
                fi
        else
                echo "- No undead processes found for $terminal_user."
        fi
done





-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_____________________________________________________________________
Ltsp-discuss mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help,   try #ltsp channel on irc.freenode.net

Reply via email to