Results 1 to 14 of 14
  1. #1


    Member Since
    Aug 10, 2010
    Posts
    13
    How to log out *background* users from command line
    I'm looking for a way to log out a background user who forgot to log out - from the terminal.

    I know this is trivial in the *nix world, just killing a process probably; I just can't find the command to do it in Mac's flavor (I'm a casual *nix shell user)

    BTW, I don't want the Prefs->Security->General "logout after inactivity" setting.... that logs out everybody (including me) and I can't have my account logged out (due to running processes).

    this is the closest I have gotten so far: but this will obviously log me out.
    osascript -e 'tell application "System Events" to log out'

    Thank you,
    Jason

  2. #2

    Lifeisabeach's Avatar
    Member Since
    Sep 30, 2007
    Location
    The Republic of Neptune
    Posts
    7,729
    I'm having a tough time finding a way to do this with Terminal. A couple tricks I read of and tried that involved killing the "loginwindow" process for another user didn't work as expected. At the moment, here's the best solution I can find but involves a 3rd party utility:
    How to log out a fast switched user

  3. #3


    Member Since
    Aug 10, 2010
    Posts
    13
    Excellent tip. This looks like it's going to work fine. I'm testing right now....


    Thanks!

  4. #4

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Remember, OS X is Unix so if there's some technique that you know of in Unix, it may work here. Now, the variants of Unix are all quite different so I can't guarantee this is the case here. What do you do on a *nix box to accomplish this?
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  5. #5

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    Quote Originally Posted by vansmith View Post
    Remember, OS X is Unix so if there's some technique that you know of in Unix, it may work here. Now, the variants of Unix are all quite different so I can't guarantee this is the case here. What do you do on a *nix box to accomplish this?
    well, something like...


    kill -9 `ps -u <username> | grep -v PID | awk '{ printf ("%s ", $1); }'`


    would accomplish this it's ummm well, kinda forceful though
    mike
    This machine kills fascists
    Got # ? phear the command line!

  6. #6

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Code:
    echo "ARE YOU SURE!?!?!? PRESS ENTER IF YOU'RE SURE!" ; read
    kill -9 `ps -u <username> | grep -v PID | awk '{ printf ("%s ", $1); }'`
    Does that help to soften it up?
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  7. #7

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    well, getting rid of the -9 might be friendlier
    mike
    This machine kills fascists
    Got # ? phear the command line!

  8. #8

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    You mean the yelling to ensure the confidence of the user wasn't enough?
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  9. #9

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    Oh I'm ALWAYS sure of my commands when I issue them
    mike
    This machine kills fascists
    Got # ? phear the command line!

  10. #10


    Member Since
    Aug 10, 2010
    Posts
    13
    Quote Originally Posted by Dysfunction View Post
    well, something like...


    kill -9 `ps -u <username> | grep -v PID | awk '{ printf ("%s ", $1); }'`


    would accomplish this it's ummm well, kinda forceful though
    This is what I'm looking for - more-so than the 3rd party program.

    However, when I try this, the <username> is an invalid argument of "ps". Should this be user ID?

    When I do $ps -u, I only see my username.
    $ps -A lists a lot of processes, but I don't see any from the other users in the background....

    Can you help correct this?

  11. #11


    Member Since
    Aug 10, 2010
    Posts
    13
    Hi Dysfunction: can you help me correct the argument <username> problem?
    Thanks

  12. #12

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    Umm yea, it should be a valid username, without the <>'s

    Oh and you'd need to issue that with either root or superuser authority.
    mike
    This machine kills fascists
    Got # ? phear the command line!

  13. #13


    Member Since
    Aug 10, 2010
    Posts
    13
    Quote Originally Posted by Dysfunction View Post
    Umm yea, it should be a valid username, without the <>'s

    Oh and you'd need to issue that with either root or superuser authority.
    oops, I see how my comment would be misinterpreted... I meant that when I use a valid username - it gives errors. I changed lower case 'u' (userID) to upper case 'U' (username) and that seems to kill everything for that user.

    The user still shows up in the FSU list however, and switching to that user hangs the GUI/console - so it's definitely not clean! But it is an option, and I thank you!

    Thanks greatly!

  14. #14

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    Ohhh ok, gotcha. But I think it's the opposite, that username is lowercase and UID is upper.

    Yea, it's not the cleanest method in the world. It's a bit like hitting a nail with a sledgehammer
    mike
    This machine kills fascists
    Got # ? phear the command line!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compare OS X command line to Linux command line?
    By V6Pony in forum OS X - Development and Darwin
    Replies: 5
    Last Post: 09-26-2013, 12:32 PM
  2. Is there a command line like this?
    By Downy in forum OS X - Operating System
    Replies: 13
    Last Post: 02-27-2011, 04:29 PM
  3. Download from command line
    By plemax in forum OS X - Operating System
    Replies: 4
    Last Post: 11-28-2008, 01:05 PM
  4. Command line arguments
    By presenter in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 06-02-2005, 12:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •