Listing 1: killidle
:
# killidle
#
# Kill any user login idle for too long
IDLEOUT=${1:-20}
if [ $IDLEOUT -lt 1 ]
then
IDLEOUT=20
fi
who -u |
awk ' {
name = $1;
terminal = $2;
idle = $6;
pid = $7;
if (idle != ".") {
split(idle, idletime, ":");
if (idletime[2] >= IDLEOUT) {
print "Timeout Warning:", \
name, "on", terminal, \
"idle for", idle, \
"minutes (killed pid:", pid ")"
system("kill -9 " pid);
}
}
}' IDLEOUT=$IDLEOUT
|