* (Arrgh) Logout idle users (NOT w/ tcsh...)
@ 1995-06-08 4:00 Phil Edwards
1995-06-08 4:00 ` Brian A. Bucher
0 siblings, 1 reply; 5+ messages in thread
From: Phil Edwards @ 1995-06-08 4:00 UTC (permalink / raw)
[Crossposted to c.u.admin, c.u.osf.misc, c.u.osf.osf1, c.u.questions,
and c.u.ultrix, so don't go loopy with the followups, eh?]
The "Arrgh" is because a solution was just posted three weeks ago and
I didn't save it...
Anyhow, I'm looking for a program that will automatically log out
users if they remain idle for a specified period of time. We have
multiple Unix boxes here, so I'm looking for something that would work
on either OSF/1, Ultrix, perhaps SunOS; or even a combination of the
above if it could be ported.
Please note: I am not asking about the autologout variable in tcsh --
I'm after something that would be run as root, separately, not
something which users would be free to configure.
We once had a program that would do this (way before my time) by way
of a system call, but when the OS was upgraded, that system call was
removed. I'm hoping to find a replacement for the program, because
the students (and faculty especially) have an extremely annoying habit
of logging on and then sucking up CPU time like it was on a sidewalk
sale.
Please mail me with any tips, recommendations, locations of source
code, etc, you might have. If I hear of anything definite, I will
post a summary to whichever group(s) out of the above list seem most
appropriate.
Thank you for your time and effort. We appreciate it a great deal.
--
Phil Edwards #include<std/disclaimer.h> pedwards@valhalla.cs.wright.edu
<URL:http://www.cs.wright.edu/people/students/pedwards/>
The gods do not protect fools. Fools are protected by more capable fools.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: (Arrgh) Logout idle users (NOT w/ tcsh...)
1995-06-08 4:00 (Arrgh) Logout idle users (NOT w/ tcsh...) Phil Edwards
@ 1995-06-08 4:00 ` Brian A. Bucher
1995-06-08 4:00 ` David Adamec
0 siblings, 1 reply; 5+ messages in thread
From: Brian A. Bucher @ 1995-06-08 4:00 UTC (permalink / raw)
Phil Edwards (pedwards@valhalla.cs.wright.edu) wrote:
:
: Anyhow, I'm looking for a program that will automatically log out
: users if they remain idle for a specified period of time. We have
: multiple Unix boxes here, so I'm looking for something that would work
: on either OSF/1, Ultrix, perhaps SunOS; or even a combination of the
: above if it could be ported.
Below is a script (my first true script ever really) that should
do what you need it to. You will want to put in a check to make
sure you don't kill root or any of the sysops (tis a Bad Thing).
It was written for /bin/sh so you shouldn't have any problems.
I'm posting this partly because I would like a reaction from the scripting
Gurus out there on how I did on my first attempt. How would you improve this,
and do I have hope for the future? ;)
Thanks,
Boo
---cut here---
#!/bin/sh
#
# Script written by Brian Bucher (babucher@mtu.edu) used to log out
# idle users. (30 minutes)
#
# trapping escape signals so that we can clean up the /tmp dir
trap "/bin/rm -fr /tmp/wfile$$ /tmp/upid$$; exit" 0 1 2 15
# creating a unique file in /tmp - delete the first 2 lines (garbage)
w | cut -c1-8,42-43 | sed '1,2d' > /tmp/wfile$$
# reading and assigning a username and idletime
cat /tmp/wfile$$ |
while read line
do
USER=`echo $line | cut -d' ' -f1`
IDLETIME=`echo $line | cut -d' ' -f2`
# If the idletime is less than 30 minutes, delete all occurences of the username
# from the temporary file
if [ "$IDLETIME" -lt 30 ]
then
sed "/$USER/d" /tmp/wfile$$ > /tmp/wfile2$$
mv /tmp/wfile2$$ /tmp/wfile$$
fi
done
# If there are any users left in the temporary file, they must
# have had processes idle over 30 minutes, so kill them.
# First check to see if the file is empty, if it is, then exit with
# status 1
if [ ! -s /tmp/wfile$$ ]
then
exit 1
fi
# If not empty...
# ...First, get the user...
cat /tmp/wfile$$ |
while read line
do
USER2=`echo $line | cut -d' ' -f1`
# ...then get his processes and store in temporary file
ps -guaxw | grep $USER2 | cut -c10-14 > /tmp/upid$$
cat /tmp/upid$$ |
# now kill each process (note: this my attempt to kill processes that
# were already killed)
# if processes are not present, redirect stderr to /dev/null
while read USERPID
do
echo "Killing PID $USERPID"
# kill $USERPID >& /dev/null
done
# Cleanup time!
/bin/rm -fr /tmp/wfile$$ /tmp/upid$$
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: (Arrgh) Logout idle users (NOT w/ tcsh...)
1995-06-08 4:00 ` Brian A. Bucher
@ 1995-06-08 4:00 ` David Adamec
1995-06-08 4:00 ` Seth J. Bradley
0 siblings, 1 reply; 5+ messages in thread
From: David Adamec @ 1995-06-08 4:00 UTC (permalink / raw)
Below is some a C code I modified to run under OSF/1; it should work
for most machines. Once you get the executable do a chmod +s on it,
then make sure every user is forced to run it when they log in.
David Adamec
_______________________________
/*
** tout - a personal timeout program
**
** Andrew Rudoff, University of Colorado, Boulder
**
** usage: tout minutes
**
** This is a voluntary timeout program. A timeout occurs when the user
** is idle for a time larger than "minutes." The inaccuracy can be as
** much as 1 minute (1 minute granularity). The user is warned 1 minute
** before the timeout; the timeout can be prevented by typing any key to
** clear the idle status of the terminal.
*/
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sgtty.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define BEEP '\007'
main(argc, argv)
int argc;
char **argv;
{
char user[50]; /* name of current user */
char invoker[50]; /* name of invoker */
struct stat statbuf; /* buffer for stats on tty */
long current, timeout; /* times in seconds */
long last_access,diff; /* times in seconds */
int pgrp, tmp = 0;
if (argc != 2)
{
fprintf(stderr, "usage: %s minutes\n", argv[0]);
exit(1);
}
time(¤t);
fstat(0, &statbuf);
diff = statbuf.st_atime-current;
nice(4); /* run gracefully in the background */
if ((timeout = 60 * atoi(argv[1])) == 0)
{
fprintf(stderr, "%s: incomprehensible or zero timeout\n", argv[0]);
exit(1);
}
if (!isatty(0))
{
fprintf(stderr, "%s: stdin not a terminal\n", argv[0]);
exit(1);
}
strcpy(invoker, getlogin());
printf("Idle terminal timeout set for %s (%s minutes)\n", invoker, argv[1]);
fflush(stdout);
if (fork())
{
exit(0);
}
while(1)
{
sleep(60);
strcpy(user, getlogin());
/* Be sure same person is logged in */
if (strcmp(user, invoker))
{
exit(0);
}
if ((fstat(0, &statbuf)) != 0)
{
fprintf(stderr, "%s: couldn't stat tty\n", argv[0]);
exit(1);
}
time(¤t);
fstat(0, &statbuf);
last_access = statbuf.st_atime-diff;
if (current + 60 - last_access >= timeout)
{
fprintf(stderr, "\n WARNING - terminal timeout in 1 minute.%c\n",
BEEP);
}
if (current - last_access >= timeout)
{
fprintf(stderr, "\n\n Terminal timeout - you're outta here!\n\n");
while(ioctl(0, TIOCGPGRP, &pgrp), pgrp != tmp)
{
tmp = pgrp;
killpg(pgrp, SIGHUP);
sleep(5);
}
exit(0);
}
}
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: (Arrgh) Logout idle users (NOT w/ tcsh...)
1995-06-08 4:00 ` David Adamec
@ 1995-06-08 4:00 ` Seth J. Bradley
1995-06-09 4:00 ` Phil Farrell
0 siblings, 1 reply; 5+ messages in thread
From: Seth J. Bradley @ 1995-06-08 4:00 UTC (permalink / raw)
In article <3r7msb$rh2@post.gsfc.nasa.gov> adamec@biggles.gsfc.nasa.gov (David Adamec) writes:
> Below is some a C code I modified to run under OSF/1; it should work
>for most machines. Once you get the executable do a chmod +s on it,
>then make sure every user is forced to run it when they log in.
If one prefers a daemon-based approach, there is the public domain
Untamo program. Its very old code, and I haven't seen it used in
awhile, but it still should work for many systems.
--
Seth J. Bradley, Senior System Administrator, Intel CT
Internet: sbradley@scic.intel.com UUCP: uunet!scic.intel.com!sbradley
----------------------------------------
"How can you be in two places at once when you're not anywhere at all"
- Firesign Theater
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: (Arrgh) Logout idle users (NOT w/ tcsh...)
1995-06-08 4:00 ` Seth J. Bradley
@ 1995-06-09 4:00 ` Phil Farrell
0 siblings, 0 replies; 5+ messages in thread
From: Phil Farrell @ 1995-06-09 4:00 UTC (permalink / raw)
I wrote a "new" awk script to find and kill idle
login sessions. I run it once per hour from cron. It has provisions
for exempting daemons and special users, as well as special programs
that may have to run in the foreground but leave the terminal idle
for long periods. It uses "w", "ps", and awk to do its work.
I wrote it for Ultrix and it will probably need some minor changes
for other systems. You can get a copy via anonymous ftp to
pangea.stanford.edu, in pub/idlekiller.tar.
Phil Farrell, Computer Systems Manager
Stanford University School of Earth Sciences
farrell@pangea.stanford.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1995-06-09 4:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-06-08 4:00 (Arrgh) Logout idle users (NOT w/ tcsh...) Phil Edwards
1995-06-08 4:00 ` Brian A. Bucher
1995-06-08 4:00 ` David Adamec
1995-06-08 4:00 ` Seth J. Bradley
1995-06-09 4:00 ` Phil Farrell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox