From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,e34f8bf95ca3b17 X-Google-Attributes: gidf8c9b,public X-Google-Thread: 10b612,e34f8bf95ca3b17 X-Google-Attributes: gid10b612,public X-Google-Thread: fee84,e34f8bf95ca3b17 X-Google-Attributes: gidfee84,public X-Google-Thread: 1020c6,e34f8bf95ca3b17 X-Google-Attributes: gid1020c6,public X-Google-Thread: f678f,e34f8bf95ca3b17 X-Google-Attributes: gidf678f,public From: adamec@biggles.gsfc.nasa.gov (David Adamec) Subject: Re: (Arrgh) Logout idle users (NOT w/ tcsh...) Date: 1995/06/08 Message-ID: <3r7msb$rh2@post.gsfc.nasa.gov>#1/1 X-Deja-AN: 104035945 distribution: world references: <3r66od$dj1@valhalla.cs.wright.edu> <3r78pe$bv2@news.mtu.edu> organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA newsgroups: comp.unix.admin,comp.unix.osf.misc,comp.unix.osf.osf1,comp.unix.questions,comp.unix.ultrix 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 #include #include #include #include #include #include #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); } } }