loggin out automatically
Cameron Patrick
cameron at nospam.patrick.wattle.id.au
Sat Nov 2 11:27:46 EST 2002
News wrote:
> I am considering writing a little program to control the amount of time a
> certain user is allowed to access a Linux system i.e. 10 minutes, 1 hour,
> etc.
>
> I was wondering if there might be any complications with a line like:
>
> os.system("logout")
'twould not work at all. os.system() starts a new shell and runs the
command in that.
The 'w' command tells you when a given user logged in and what tty they are
on. A command like
ps --tty pts/3
will give you a list of all the processes running on a given tty, e.g. pts/3
I'm sure there's some way of parsing the output of these two in Python and
killing the processes with os.kill()
In fact, I believe there's some way of setting login session time limits in
Linux which would eliminate the need for such a Python programme.
>
> Would :
> The python interpreter wait for the call to return and refuse to die
> so
> the call would fail?
> Or: would some other complication I haven't thought of stop this
> working?
> Or: would this work fine?
> Or: am I an idiot?
> Or: some combination of the above?
>
Some combination of the above, I'd say. Some people might suggest that you
were silly to not just /try/ your command in a python interpreter, e.g.--
cameron at erdos:~$ python
Python 2.2.1 (#1, Oct 6 2002, 17:09:32)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('logout')
sh: logout: not login shell: use `exit'
CP
More information about the Python-list
mailing list