33 lines
903 B
Python
Executable file
33 lines
903 B
Python
Executable file
#! /usr/bin/env python
|
|
|
|
import sre, commands
|
|
|
|
# pour chaque ligne du w
|
|
for w in commands.getoutput("w -h").split('\n') :
|
|
if not w : continue
|
|
# on splite
|
|
w = sre.split(' *', w)
|
|
|
|
# on verifie que c'est une connection du bde
|
|
hosts = ['bde.crans.org','cableur.crans.org','cableuse.crans.org']
|
|
if w[2] not in [ h[0:16] for h in hosts ] :
|
|
continue
|
|
|
|
# on verifie qu'on a depase le timeout
|
|
if sre.match('^\d*\.\d*s$',w[4]) or sre.match('^[0-4]:\d*$',w[4]) :
|
|
continue
|
|
|
|
# on reccuperre les processus s le tty
|
|
ps = sre.split(' *', commands.getoutput('ps auwwx | grep "%s" | head -n 1' % w[1] ) )
|
|
|
|
# on verrifie que c'est le bon user
|
|
if ps[0] != w[0] :
|
|
continue
|
|
|
|
# on verifie qu'on a pas de tty
|
|
if ps[6] != '?' :
|
|
continue
|
|
|
|
# on tue le process
|
|
commands.getoutput('kill %s' % ps[1] )
|
|
print ps
|