LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2012, 07:21 PM   #1
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
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?
 
Old 04-16-2012, 07:37 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
1 members found this post helpful.
Old 04-16-2012, 08:35 PM   #3
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-16-2012, 08:39 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Did you TRY my command? Or are you in fact on a Mac, using some odd ancient version of ps?
 
Old 04-16-2012, 08:48 PM   #5
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
I tried it. It printed out the numbers as opposed to the names. I'm running windows xp and using SSH.
 
Old 04-16-2012, 08:51 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
And what are you connecting to?
 
Old 04-16-2012, 08:58 PM   #7
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
orlov.pdx.oit.edu

It's what my school gave me.
 
Old 04-16-2012, 09:05 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 04-16-2012, 09:07 PM   #9
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
This is the output:

Linux Orlov 2.6.18-6-686 #1 SMP Fri Feb 19 23:40:03 UTC 2010 i686 GNU/Linux
 
Old 04-16-2012, 09:19 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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}*
 
1 members found this post helpful.
Old 04-16-2012, 09:25 PM   #11
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-16-2012, 10:00 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

Last edited by Tinkster; 04-16-2012 at 10:01 PM.
 
1 members found this post helpful.
Old 04-16-2012, 10:53 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
So ... did that help?
 
Old 04-16-2012, 11:06 PM   #14
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Yeah I made do, thank you
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pppd, running instances Daniel T Linux - Networking 1 05-23-2010 11:29 AM
BASH query to find unique Usernames basildon Linux - Newbie 9 09-05-2008 03:49 AM
IDS bash clpl1980 Linux - Networking 1 01-23-2007 06:52 AM
number of running instances hk_linux Programming 0 01-05-2005 11:47 PM
9 httpd instances running!?? jlinden Linux - Newbie 2 09-17-2003 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration