[K12OSN] Kill all your users

David Trask dtrask at vcsvikings.org
Mon Dec 11 19:29:06 UTC 2006


(in a non-sadistic manner)  ;-)

Kill 'em all!  (at the end of the day)  ;-)

Here's how I do it.  I have a script called "stop" located in /usr/bin. 
It's designed originally to "kill" a single user, but I have taken that
script and made another script that can be launched as a cron job to
"purge" the server.  First the "stop" script....

#!/bin/sh
# usage  stop username
# stop
# script to logoff a student
#

if [ $1 != "root" ]
then
   for i in $(pgrep -u $1)
   do
      kill -9 $i
   done
else
   clear
   echo "Can't kill the root!!"
fi


Now the script to "stop" them all:

#!/bin/bash
for x in `ls /home`; do
echo "Killing $x ..."
stop ${x}
done

I called this one "stop-all", made it executable (chmod a+x stop-all) and
put it into a cron job.  Works pretty slick!  :-)  YMMV

PS....doesn't matter if /home is local or mounted via NFS (like
Samba/LDAP) it simply reads the directory listing of /home to get
usernames.  If your home dirs are in a different location or separated by
YOG or something like that....just add the extra step to call that
directory.  Something like:

for x in `ls /home/2007`; do


David N. Trask
Technology Teacher/Director
Vassalboro Community School
dtrask at vcsvikings.org
(207)923-3100





More information about the K12OSN mailing list