INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Logging users off following 2 hours inactivity by KenCunningham
Posted: 13 Nov 01

Some versions of *nix don't support a TMOUT variable, so the following script might be useful to those administrators who wish to kill users after a period of inactivity longer than two hours. Please note that this script was written with Oracle users in mind, but should work for others too. This is it:

USERS=`finger | wc -l`
if [ $USERS -gt 40 ]
then
rm users 2>/dev/null
finger -i > times
grep hours times > times1
cat times1 | tr -s ' ' ' ' | cut -f1 -d' ' > times2
for i in `cat times2`
do
ps -ef |grep $i | grep -v root| tr -s ' ' ' ' | cut -f4 -d' ' >> users
done
cat users | while read number
do
kill $number 2>/dev/null
done
else
exit
fi

I run this script every hour from cron. If there are no more than 40 users on the system, no action is taken.

Back to UNIX Scripting FAQ Index
Back to UNIX Scripting Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close