LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Get usernames (rather than IDs) for running bash instances (https://www.linuxquestions.org/questions/linux-newbie-8/get-usernames-rather-than-ids-for-running-bash-instances-940127/)

hawkfan50 04-16-2012 07:21 PM

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
The above command represents user ID's as numbers. Is there a command to list the usernames along with the shell they are using?

Tinkster 04-16-2012 07:37 PM

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

hawkfan50 04-16-2012 08:35 PM

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.

Tinkster 04-16-2012 08:39 PM

Did you TRY my command? Or are you in fact on a Mac, using some odd ancient version of ps? :)

hawkfan50 04-16-2012 08:48 PM

I tried it. It printed out the numbers as opposed to the names. I'm running windows xp and using SSH.

Tinkster 04-16-2012 08:51 PM

And what are you connecting to?

hawkfan50 04-16-2012 08:58 PM

orlov.pdx.oit.edu

It's what my school gave me.

TobiSGD 04-16-2012 09:05 PM

Please connect to that computer, run the command
Code:

uname -a
and post the output here, so that we can see which OS in running.

hawkfan50 04-16-2012 09:07 PM

This is the output:

Linux Orlov 2.6.18-6-686 #1 SMP Fri Feb 19 23:40:03 UTC 2010 i686 GNU/Linux

Tinkster 04-16-2012 09:19 PM

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}*

hawkfan50 04-16-2012 09:25 PM

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

Tinkster 04-16-2012 10:00 PM

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
Somewhat convoluted, but seems to work for me ;D


And a completely different, far simpler approach ;D
Code:

fuser -u /bin/bash


Cheers,
Tink

Tinkster 04-16-2012 10:53 PM

So ... did that help?

hawkfan50 04-16-2012 11:06 PM

Yeah I made do, thank you :)


All times are GMT -5. The time now is 04:09 PM.