Disconnecting Idle Users
- 0
- Add a Comment
Disconnecting Idle Users
I’ve recently run into an annoyance on my test machine at home that I thought I’d share with you, along with a fairly quick and easy solution. After all, fewer annoyances are a good thing, right?
The problem goes something like this. First, because the only working modems Qwest has been able to provide us with at the office are Intel 3200 USB modems, my Internet access at work is limited to Windows. I know - there’s a solution to that somewhere that I just haven’t yet worked through. I’m currently opening up a connection to my machine at home to check email. That machine is where all my filters reside. Plus, it’s nice to have one central repository for all my mail, filtered or not. Using Putty, I can log in, open Pine, check my email, and get out quickly. I’ve found, though, that those connections are not always terminated. There have been times when I’ve checked “users” or “top” in Linux to find as many as eight tony users running. Whether or not ssh was closing cleanly, I was still left with many idle users.
idled is a lightweight program available here. When installed and configured, idled limits a user’s idle time, disconnecting that user after a pre-determined period of inactivity. The build and configuration is quite painless and the download itself is very small, weighing in at a mere 67 Kb. Some small modifications are required to the Makefile, depending on the system you’re using, but the instructions in the INSTALL file are easy to follow and very self-explanatory.
With idled installed on my system, the idle users are gone. That, by itself, might be enough. But you know me. I want to know what my system’s been doing over the course of the day. So, I wrote the following script to report on the activities of idled each night:
#!/bin/sh
# set and format today’s date variable for grep
TDATE=`/bin/date “+%a %b %-d”`
# set and format the mail date variable for the
# report email subject line
FDATE=`/bin/date +%Y%m%d`
# open the idled.log file, look for the
# date string formatted to match the log format,
# and send the results in an email with the
# proper FDATE formatting in the subject line
cat /var/log/idled.log | grep “$TDATE” | mail tony@localhost -s “$FDATE Idled Report”
# go away
exit
The comments in the script (lines starting with #) explain pretty clearly what each element of the script accomplishes. When this script is executed, I end up with an email from root summarizing all idled activity for a given day. By adding the command to execute this program to /etc/crontab, I receive this report daily. Note that in order to match the current day in the log file, this script runs at 11:59 pm each night.
Now you know how to handle those idle users. Don’t yell at ‘em - just disconnect ‘em automatically. After all, every user has to pull their weight these days. Dead weight, be gone.
