LinuxQuestions.org
Visit Jeremy's Blog.
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 05-27-2003, 02:49 PM   #1
linxnewbie
LQ Newbie
 
Registered: May 2003
Posts: 5

Rep: Reputation: 0
linux commands


Does anyone know what command would list all users logged in to a linux system who had a specific number (i.e. 8) in their user id. Thanks.
 
Old 05-27-2003, 02:50 PM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Why not look at /etc/passwd as root?
 
Old 05-27-2003, 02:53 PM   #3
linxnewbie
LQ Newbie
 
Registered: May 2003
Posts: 5

Original Poster
Rep: Reputation: 0
I'm not allowed to be root. I can find all users listed in /etc/group and can sort out users with a specific number in their id, but the list there is not of users who are actually logged in to the system, just users who are able to log in.
 
Old 05-27-2003, 02:57 PM   #4
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Honestly if you're not root, I dony know why you should be allowed to know the names of users and their user ids.
Maybe use users, or the files in /var about active processes and other current system info.
 
Old 05-27-2003, 05:41 PM   #5
awdoyle
Member
 
Registered: Aug 2002
Location: Portland, OR
Distribution: Xubuntu
Posts: 135

Rep: Reputation: 15
Well lets see.. . you'd probably have to write a script. Awk would probably work best at the beginning, something like
awk -F: ' /8/ {print $1 " " $3} /etc/passwd
where 8 is your specific number. Maybe you could stuff that into a variable, then grep the variable from "w" command. Stuff the grep command into a variable, and print it out.
Well it's probably a step in the right direction.

Andrew

Last edited by awdoyle; 05-27-2003 at 05:43 PM.
 
Old 05-27-2003, 05:41 PM   #6
awdoyle
Member
 
Registered: Aug 2002
Location: Portland, OR
Distribution: Xubuntu
Posts: 135

Rep: Reputation: 15
Sorry, double post.
Andrew

Last edited by awdoyle; 05-27-2003 at 05:42 PM.
 
Old 05-27-2003, 05:47 PM   #7
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Rep: Reputation: 31
hi,

cat /etc/passwd | awk -F: '$3 ~ /8/ {print $1}'

this command will print all users who have an 8 in their user ID.
Now you can type "users" and see who's logged in.
then compare the 2.
easy

let me know if I can help more.
 
Old 05-28-2003, 09:31 AM   #8
linxnewbie
LQ Newbie
 
Registered: May 2003
Posts: 5

Original Poster
Rep: Reputation: 0
Hi

Thanks for everyone's help and suggestions. I've been trying to work this out for my college course.

youngstorm - Thanks,
I tried cat /etc/passwd | awk -F: '$3 ~ /8/ {print $1}' as suggested and it worked perfectly. I don't understand how the awk script works yet - will have to look into it to try to understand it. Thanks again.
 
Old 05-28-2003, 09:51 AM   #9
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Rep: Reputation: 31
glad to help
Above my post, Andrew gave you 1 that works equally well

awk -F: ' /8/ {print $1 " " $3}' /etc/passwd

In his, he failed to put the second ' right behind the } which will prevent it from working. I included it so you can copy and paste the command.

have good day
 
  


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
linux commands zexter Linux - Newbie 5 11-04-2004 02:37 PM
linux commands help kyborg Linux - Newbie 4 09-28-2004 01:31 AM
Linux commands Delmarc Linux - Newbie 9 10-22-2003 10:39 PM
Linux commands Shikha Linux - General 3 11-27-2002 09:40 AM
Linux Commands AMDPwred Linux - General 23 01-11-2002 12:23 PM


All times are GMT -5. The time now is 06:07 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