New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

How to log out *background* users from command line


Post Reply New Thread Subscribe

 
Thread Tools
asiajason

 
Member Since: Aug 10, 2010
Posts: 13
asiajason is on a distinguished road

asiajason is offline
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
QUOTE Thanks
Lifeisabeach

 
Lifeisabeach's Avatar
 
Member Since: Sep 30, 2007
Location: Wilmington, NC
Posts: 6,977
Lifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond reputeLifeisabeach has a reputation beyond repute
Mac Specs: iMac i3 (mid-2010) + OS 10.9; TV 3; iPhone 5S; iPad 4

Lifeisabeach is offline
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
QUOTE Thanks
asiajason

 
Member Since: Aug 10, 2010
Posts: 13
asiajason is on a distinguished road

asiajason is offline
Excellent tip. This looks like it's going to work fine. I'm testing right now....


Thanks!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,014
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,014
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
well, getting rid of the -9 might be friendlier

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,014
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
Oh I'm ALWAYS sure of my commands when I issue them

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
asiajason

 
Member Since: Aug 10, 2010
Posts: 13
asiajason is on a distinguished road

asiajason is offline
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?
QUOTE Thanks
asiajason

 
Member Since: Aug 10, 2010
Posts: 13
asiajason is on a distinguished road

asiajason is offline
Hi Dysfunction: can you help me correct the argument <username> problem?
Thanks
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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!
QUOTE Thanks
asiajason

 
Member Since: Aug 10, 2010
Posts: 13
asiajason is on a distinguished road

asiajason is offline
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!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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!
QUOTE Thanks

Post Reply New Thread Subscribe


« time Machine experts needed, sparsebundle problem | Everything freezing suddenly. beachball. random. for no reason at all »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Nearly half of small business users accessing work email use iPhone the8thark Apple Rumors and Reports 0 02-11-2011 07:42 PM
Setting 32bit for multiple users using CS5 SCC2010 OS X - Apps and Games 0 11-03-2010 12:34 PM
The latest "Get a Mac "ads Kilted1 Schweb's Lounge 34 05-17-2008 06:39 PM
Sky by Broadband not available to Mac users: please complain TimandJane06 Schweb's Lounge 1 07-09-2006 09:56 AM
Mac Users Get More ISP Choices schweb Apple Rumors and Reports 1 03-06-2003 10:57 AM

All times are GMT -4. The time now is 09:05 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?