{ 12 comments… read them below or add one }

1 yoander February 25, 2009

nice tip

Reply

2 Liju February 25, 2009

Good tips .. :-)

Reply

3 marz February 25, 2009

while date ; do sleep 10 ; done

or

watch -n 10 date

;)

Reply

4 Boopalan March 7, 2009

i wont hardware networking /linux /ccna

Reply

5 MikeM March 31, 2009

We wanted something a bit more user explicit (log out idle users but not the boss(s)). The list of users below are exempt. Set this script in crontab to run every 10 minutes. With an idle of time of 30, the idled sessions will be no more than 39 minutes idle.
Here is our script;

#! /usr/bin/awk -f
BEGIN {
system("who -u | sort +5 > /tmp/loginfile");
system("echo User Sessions Killed > /tmp/killedlogins");
system("echo `date` >> /tmp/killedlogins");
while (getline = 1) || (timearray[2] >= 30)) &&
($1 != "root") &&
($1 != "user2") &&
($1 != "user2") &&
($1 != "user4") &&
($1 != "lastuser")) { {
system("ps -ef | grep " $1 " | awk '{print $2}' | xargs kill -KILL");
print $1, "[Idle " $6 "] Session terminated from " $8 >> "/tmp/killedlogins";
};
};
};
}

Reply

6 Vivek Gite March 31, 2009

@MikeM

Thanks for sharing your script.

Reply

7 Matteo D'Alfonso July 8, 2010

Thanks!

Only one note, on tcsh v. 6.14 you need to quote the value:

set -r autologout=’5′

Reply

8 Indie May 20, 2011

@MikeM: You can kill specific terminals with the command

pkill -HUP -t pts/2

you don’t need to send it the kill signal.

You could also modify the original autologout.sh script so the TMOUT value only gets set for specific users

case "$(id -un)" in
  root|sysadmin|backup) ;;
  *)    readonly TMOUT; export TMOUT=300;;
esac

Reply

9 Dougie Smythe June 21, 2011

Thanks Indie, that was what I was looking for. But I have both bash and tcsh users on my system. So how do I implement it in csh?
Cheers,

ds

Reply

10 Indie June 21, 2011

TCSH uses the autologout variable instead of TMOUT so you’d need to create autologout.csh with something like the following, I’m not at all familiar with TCSH syntax.

switch (`id -un`)
  case root:
  case sysadmin:
  case backup:
    unset autologout
    breaksw
  default:
    set -r autologout=100
endsw

Reply

11 Dougie Smythe June 24, 2011

Thanks so much for the tcsh syntax, Indie.
I’ll give it a try.

Reply

12 Some Guy December 10, 2011

ClientAliveInterval 300
ClientAliveCountMax 0

This keeps sessions alive by sending nul packets every 300 seconds. It doesn’t disconnect idle users.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 4 + 14 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the simple math so we know that you are a human and not a script.




Previous post:

Next post: