Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logging users off following 2 hours inactivity

Logging users off following 2 hours inactivity

by  KenCunningham  Posted    (Edited  )
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.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top