LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 08: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, 08:37 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 09: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, 09:39 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Did you TRY my command? Or are you in fact on a Mac, using some odd ancient version of ps?
 
Old 04-16-2012, 09: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, 09:51 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And what are you connecting to?
 
Old 04-16-2012, 09: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, 10:05 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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, 10: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, 10:19 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 10: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, 11:00 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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 11:01 PM.
 
1 members found this post helpful.
Old 04-16-2012, 11:53 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
So ... did that help?
 
Old 04-17-2012, 12:06 AM   #14
hawkfan50
LQ Newbie
 
Registered: Apr 2012
Posts: 10

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:29 PM
BASH query to find unique Usernames basildon Linux - Newbie 9 09-05-2008 04:49 AM
IDS bash clpl1980 Linux - Networking 1 01-23-2007 07:52 AM
number of running instances hk_linux Programming 0 01-06-2005 12:47 AM
9 httpd instances running!?? jlinden Linux - Newbie 2 09-17-2003 12:32 PM


All times are GMT -5. The time now is 07:00 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration