Edubuntu LTSP cleanup of persistent stale processes

Andy Figueroa figueroa at
Wed Apr 22 04:24:27 BST 2009

I am a happy, but sometimes frustrated, system administrator of an
Edubuntu LTSP installation in a private school's very busy computer lab.
  I'm running a fully up-to-date hardy 8.04 LTS setup.

Searching Google for 'ubuntu ltsp cleanup processe' it doesn't look like
there is going to be a systemic solution to this in the immediate
future, so I wrote a bash script (series of scripts, really) to clean up
these many detached processes, without affecting users that are
currently logged in or killing any system processes.

The main script: killstale.scr can be run manually by root or via sudo.
  I run it hourly during school days via root's crontab.  It looks like

# This series of bash commands will kill all processes owned by
# ordinary users who are not currently logged in.
# Make a list of all processes with an owner
ps axu | cut --delimiter=" " -f 1 | sort -u > killstale.list
# Make a fresh list of all ordinary users with directory in /home
ls --color=never /home > killstale.home
# Reduce list to processes owned by those ordinary users
fgrep -f killstale.list killstale.home > killstale.users
# Find out who is currently logged in
w -h | cut --delimiter=" " -f1 > killstale.w
# Create new list minus users currently logged in
fgrep -v -f killstale.w killstale.users > killstale.xusers
# Identify user processes with user number
grep 1... killstale.list > killstale.num
# Find out who those user numbers belong to
fgrep -f killstale.num /etc/passwd | cut --delimiter=: -f1 >
# Add those processes to the list
cat killstale.xusers > killstale.semi
# Eliminate duplicate user names
sort -u killstale.semi >
# Kill all processes owned by those not-logged in ordinary users

killstale1.scr looks like this:
/root/killstale2.scr < /root/

and killstale2.scr like this:
read users
while [ -n "${users}" ] ; do
     killall -u ${users}
         read users

I'm definitely interested in your thoughts or better ideas.

Andy Figueroa

More information about the edubuntu-users mailing list