Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Python script log out of the shell when it exits?

Tags:

python

bash

shell

I'm writing a shell script in Python for bash. The script automatically runs when the user logs into the account, and I want it to log the user out when it exits. I tried using os.system('exit'), but it doesn't work. How would I achieve this?

like image 391
rzrscm Avatar asked Mar 04 '26 14:03

rzrscm


1 Answers

Set your python script as the login shell of the user(in /etc/passwd/). This way she will be automatically logged out after the script exits.

like image 174
Frederick Roth Avatar answered Mar 07 '26 09:03

Frederick Roth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!