[Tutor] python scripting and unix
Michael P. Reilly
arcege@speakeasy.net
Tue, 29 Jan 2002 15:36:00 -0500
On Mon, Jan 28, 2002 at 07:47:05PM -0500, Christine Wilson wrote:
> I am writing a python script set to execute upon login to my unix account.
> The user is prompted for further information - if the answer is correct,
> they may continue. If the answer is wrong (meaning that it is not me) I
> want the session to exit/logout.
>
> How can I do this? I'm just becoming familiar with Python and scripting.
> Any ideas?
>
> The script is executing before the user actually is prompted with the Unix
> prompt.
>
> ----------------------------------------------------------------------
> #!/usr/bin/env python
>
> import os
> os.system("clear")
>
> from sudialg import *
> if ask_who(): #gets user input for first answer, returns 1 if correct
> #continues
>
> else:
> exit #I want the telnet session to end with NO access to my account
> #but this is just exiting the script
I assume you want to have this in the user's dot file.
Instead of "exit", you will want
os.kill(os.getppid, 1)
Which sends a hang-up signal to the login shell, logging the user out.
-Arcege