Piddle: a Perl idleout program

More Programs

I've never been happy with idleout. It is a shell script, so you can modify it for your own needs, but it lacks many features that people want, and can often be wrong about whether or not a user truly is idle. It is also not particularly easy to modify for complex uses.


Hate these ads?

A better program is nidleout by John Dubois. This has many more features, and is far less apt to be wrong about idleness, but it still has problems. For one thing, it's written as a ksh script, and it pushes the capabilities of ksh fairly hard, so it too isn't all that easy to modify. Further, it (by design) simply ignores certain processes that it cannot be sure about, and that list includes console X sessions.

There are also commercial solutions. Computronics Logmon is product that doesn't have the limitations of idleout and offers extensive configuration capability.

So, I started thinking about how I could really tell if someone was idle, and it struck me that /etc/crash could give me most of what I needed. The resulting program is presented here. It isn't perfect, but it seems to have some capabilities lacking in other methods, so it might work for you.

Diller Ryan noted this bug: I tried your PIDDLE.PL program. I don't think you can do anything about it, but there seems to be a problem in the perl library popen code. After running for a day, the program apparently used my quota of processes. 'ps' displayed a huge list of zombies, which I believe were the residue of your periodic queries. It seems like there should be a 'wait' in the the library code. Have you noticed this before? I doubt it's anything to do with the spawning of "ps" and "crash". A zombie is the result of a parent process that dies before its children, and piddle doesn't die. Rather I suspect it has to do with the ordering of the kills, but it's still something that may need work.

This uses a configuration file (actually, it can use several different configuration files, but we'll get to that later). Here's a sample file:



# piddle configuration file
# root on console (secure room) gets 60 minutes
root:tty01=60
root:tty02=60
root:tty03=60
root:tty04=60
# root on any other terminal only gets 10 minutes
root:*=10
# tty2a is in open area, 10 minutes only
*:tty2a=10
# tony gets to stay in a long time
tony:*=9999
# otherwise, anybody else gets 15 minutes
*:*=15
# exit after 8 hours
# this is so you can have different rules files for different
# times of days, days of the week, etc.
RUNTIME=480
# processes that need to be ignored because they tick even when idle
TICKS=xdt3_binary
TICKS=Xsco
# using long process listing, bypass users running IGNORE
IGNORE=checks
IGNORE=cash -d update







You can probably figure most of this out by yourself, but some explanation may be needed for some of it.

TICKS, for example, are programs that will have "activity" in /etc/crash even when the user really is idle. A good example of that is a user running the gui on the console: Xsco and xdt3_binary will appear to be busy even when the user really isn't. By setting TICKS lines equal to these programs, we can idle those users out (note that nidleout handles these "event driven" programs by ignoring them entirely, and that idleout sees such users as idle even when they are not).

IGNORE is for the case when you definitely do not want to kill a user running a particular process. The string argument will be compared to the long argument from ps, not the command argument (note the difference between



ps -o pid= -o args=


and



ps -o pid= -o comm=


if that confuses you).

RUNTIME is so that you can have different rules for different times of day, different days of the week, etc. Just fire "piddle"'s off from crontab, giving different configuration files as arguments, and setting RUNTIME so that one exits before the other starts.

Piddle is designed so that you can test it without actually affecting any user. If the debug level is set to "1" (as it is by default), debugging output will be written to /tmp/piddle.debug, and this will include information about the users and processes that would be killed if debug were set to "2" or were not set at all.

One note: the accuracy is rather granular: someone supposed to get 15 minutes of grace may get close to 30 under some conditions. I haven't felt that is important.


ad

Please do test this before turning it loose. If you find improvements that could be made, please report them to me.


Download piddle.pl.


(c) November 1998 Anthony Lawrence. All rights reserved.




Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
2218211 1,151

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:




Unix/Linux Consultants


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses



Twitter
  • Nov 23 13:01
    I need coffee before I will even open the door, never mind go out there. That's completely non-negotiable, by the way.
  • Nov 23 12:56
    It's COLD and my wife wants us to go work in the yard. Do you think I can have her arrested for cruelty? Probably not as she's going too.









Change Congress


Related Posts