Here is the script that kills old users processes

Mattias Hemmingtsson matte at ahavaxthuset.se
Fri Nov 21 08:01:19 GMT 2008


Hi

So a solved it or i find som code on the internet that helpt me :-)

This collects the users from the ldap server and then kills 
all that users processes.
I run it every night to do some clean up

#!/bin/bash
#Script för att rensa upp i datorn varje dag
#
#Tar ut alla users till filen kill.log
#rm kill.log
#getent passwd >> kill.log


# hämtar ut användarna och dödar deras processer

awk -F: '{print $1,$3}' kill.log | while read user pid
do
(( pid > 1001 )) && skill -9 -u $user
done


But a also fint a script that kill sleeping processes byt i havet got it
to work yeat but here it is.

#!/bin/bash

# max hours to be idle
( HOURS = 1 )

# start number of user uid's
( UID = 500 )

# file with users to exclude from killing (one user per line)
excludefile=kill.log

w -h | awk '!/root/{print $1,$5}' | while read user idle
do
# check if user is in excludefile
[[ -n $( grep $user $excludefile ) ]] && continue
# check for idle time
[[ -n "$( echo $idle | grep -E 'm|s' )" ]] && continue

# make hours of idle (throw everythig away after and incuding ':'
# e.g. 2:35 will become 2
idle=${idle%:*}
# get uid from user
uid=$( id -u $user )

(( uid >= UID )) && (( idle >= HOURS )) &&  "pkill -9 -u $user"
done


// Mattias





More information about the edubuntu-users mailing list