Get usernames (rather than IDs) for running bash instances
I can't figure out the command to list the logged in users that are running bash.
Code:
ps | grep bash |
Hi, welcome to LQ!
I recommend reading the ps man-page, highly informational! Something like this, maybe? Code:
ps ax -o ruser,command|awk '/bash/{print $1}' Cheers, Tink |
I've been reading through the man ps but I can't figure out how to make it print the actual user names instead of the numbers.
|
Did you TRY my command? Or are you in fact on a Mac, using some odd ancient version of ps? :)
|
I tried it. It printed out the numbers as opposed to the names. I'm running windows xp and using SSH.
|
And what are you connecting to?
|
orlov.pdx.oit.edu
It's what my school gave me. |
Please connect to that computer, run the command
Code:
uname -a |
This is the output:
Linux Orlov 2.6.18-6-686 #1 SMP Fri Feb 19 23:40:03 UTC 2010 i686 GNU/Linux |
Ok, try to find out which version of ps you're using there....
ps --version Maybe followed with a ls -l /etc/*{release,version}* and cat /etc/*{release,version}* |
ps --version = procps version 3.2.7
ls -l /etc/*{release,version}* = -rw-r--r-- 1 root root 4 Oct 28 2006 /etc/debian_version cat /etc/*{release,version}* = 4.0 |
Wow ... that's .... errrrh .... dated =o)
If that version of ps doesn't do the trick you may have to get those uids and do the extraction of names yourself. Code:
awk -F: --re-interval -v uids=$(ps ax -o uid,command|awk '/bash/{a[$1]++}END{n=asorti(a,d);for(i=1;i<n;i++){printf "%s|",d[i]};printf "%s",d[n]}') 'BEGIN{uids="\\<("uids")\\>"}{if($3~uids){print $1}}' /etc/passwd And a completely different, far simpler approach ;D Code:
fuser -u /bin/bash Cheers, Tink |
So ... did that help?
|
Yeah I made do, thank you :)
|
All times are GMT -5. The time now is 04:09 PM. |