Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:10:07+00:00 2026-06-13T12:10:07+00:00

I want my script to automatically log the current user out when the script

  • 0

I want my script to automatically log the current user out when the script has finished. It it to be ran on an Linux-based server (Ubuntu). I’ve tried this line of code, but it won’t work.

subprocess.call(['logout'])

Gave the following error:

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I also tried:

subprocess.Popen(['sudo', 'logout'])

But then the user’ll have to enter his password to be logged out. Without sudo on this one I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I do not want to run the script itself as root.

I want to be able to log a user directly out without them having to enter the password. When you use logout in a regular terminal you usually don’t have to enter the password, so I don’t really get why this is even an issue.

All help is greatly appreciated.

EDIT: I have found a solution to my problem by adding a little extra code to ~/.bash_login (see my answer), but why what I’m trying above has not been answered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:10:08+00:00Added an answer on June 13, 2026 at 12:10 pm

    I found a solution to my problem. I added

    sys.exit(1)
    

    To my script.

    Then I added the following code to ~/.bash_login

    if [ "$?" == "0" ]; then
        logout
    fi
    

    So the logout-command runs when the Python-script is finished.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to automatically run a simple shell script at linux startup i'm working
I want the following script command to be executed automatically when ever I log
I want to write a script which cleans the 'run' dialogue automatically every log
I want to create a script that automatically unzips music albums and creates a
I want to make a script that automatically backs up my kindle files when
To help me learn Haskell, I want to write a script for automatically downloading
IE8 is out and apparently it automatically turns on script (JavaScript) debugging whenever you
I want to script the download of messages from hotmail. Both Gmail and Hotmail
I want my script to define an empty array. array values should be added
I want to script a daily report of all EC2 usage and send the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.