By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,643 Members | 1,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,643 IT Pros & Developers. It's quick & easy.

Listing logged on users

P: 16
I want to create a file that shows all the users logged into the system and their processes. I've tried using the w command...this lists a little too much information...so i tried using

ps -U *myusername* but that only gave me my current logged on status in the following correct format:-

PID TTY TIME CMD
31799 pts/3 00:00:00 vim
31866 pts/3 00:00:00 vim
2495 pts/7 00:00:00 vim
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

However in the newly created file i want to list all users in the following format:-

Alistairr Rutherford
PID TTY TIME CMD
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps

note that their names are their full names not loggin names...how do i go about this?

I'm very new to this so would like to start with basics, that excludes awk/sed commands or tmp files because i've not read about them yet.
Jan 16 '08 #1
Share this Question
Share on Google+
7 Replies

prn
Expert 100+
P: 254
prn
w gives you too much information???? If I do
ps -U prn
on my linux box, I get about 40 lines of process information. And what makes the ps output the "correct" format?

I think this smells of homework. It's useless and it has a "correct" format. That sounds very suspicious to me. Please read the Posting Guidelines, especially with reference to Homework.

Regards,
Paul
Jan 16 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
w gives you too much information???? If I do
ps -U prn
on my linux box, I get about 40 lines of process information. And what makes the ps output the "correct" format?

I think this smells of homework. It's useless and it has a "correct" format. That sounds very suspicious to me. Please read the Posting Guidelines, especially with reference to Homework.

Regards,
Paul
I fully agree prn! This definitely smells like homework. I remember a similar exercise from when I was in college.

Regards,

Jeff
Jan 16 '08 #3

P: 16
I'm gona emphasise this again...this is not homework i have graduated and for a job i require to understand unix further. They have given me an online tutorial and have suggested excercises to carry out...and i am unable to do them.

So far you have critcised my knowledge. ps -U *username* structures the required information the way i want it to...however does not show me the list of all users in that foramt...

my second problem is putting the name of the user above the information...

one more time...not homework! 21 year old graduated and is doing further training...
Jan 16 '08 #4

P: 16
w gives you too much information???? If I do
ps -U prn
on my linux box, I get about 40 lines of process information. And what makes the ps output the "correct" format?

I think this smells of homework. It's useless and it has a "correct" format. That sounds very suspicious to me. Please read the Posting Guidelines, especially with reference to Homework.

Regards,
Paul
Have a look at what i get:-

[norman.thai@unix ~]$ ps -U norman.thai
PID TTY TIME CMD
9681 ? 00:00:00 sshd
9682 pts/23 00:00:00 bash
9711 pts/23 00:00:00 ps
[norman.thai@unix ~]$ w
14:07:31 up 1 day, 4:47, 24 users, load average: 0.14, 0.12, 0.10
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
amol.pan pts/1 82.28.49.174 14:03 5.00s 0.03s 0.03s -bash
raeika.m pts/2 172.21.0.71 14:01 0.00s 0.08s 0.01s sqlplus
michael. pts/3 172.21.0.182 13:06 22.00s 0.02s 0.01s sqlplus
muhammad pts/4 172.20.0.213 14:01 25.00s 0.05s 0.02s sqlplus
harriet. pts/5 172.20.0.123 13:56 2.00s 0.05s 0.01s sqlplus
belkacem pts/6 62.35.142.124 13:18 4:21 0.05s 0.02s sqlplus
mehdi.ga pts/7 78.113.12.41 13:19 5:29 0.33s 0.00s man find
richard. pts/8 172.20.3.19 13:36 2:02 0.17s 0.13s sqlplus
nestor.k pts/9 89.12.137.223 13:54 13:29 0.02s 0.02s -bash
joseph.r pts/10 172.16.1.152 13:46 30.00s 2.01s 1.99s sqlplus
samir.hi pts/11 172.159.45.202 13:23 14:36 0.05s 0.05s -bash
harry.wi pts/12 172.16.1.110 10:02 3:54m 57.07s 57.04s top
gavin.re pts/13 82.34.111.147 10:26 1:20 0.08s 0.08s -bash
thomas.s pts/14 172.20.0.210 13:26 38:06 0.19s 0.17s sqlplus
edward.m pts/15 172.16.1.106 09:02 3:23m 0.05s 0.04s sqlplus
vishal.k pts/16 172.20.0.91 14:03 6.00s 0.14s 0.00s sh sql
francisc pts/17 79.65.239.70 11:50 16.00s 0.25s 0.25s -bash
kofi.ogo pts/18 84.13.175.221 12:26 14:33 0.07s 0.07s -bash
samir.hi pts/19 172.159.45.202 13:59 41.00s 0.02s 0.02s -bash
adewale. pts/20 172.20.0.220 13:29 24.00s 0.07s 0.05s sqlplus
nestor.k pts/21 89.12.137.223 14:04 0.00s 0.08s 0.04s vim
balkaran pts/22 172.120.72.201 14:06 47.00s 0.02s 0.02s -bash
norman.t pts/23 86.20.72.45 14:07 0.00s 0.03s 0.01s w
andrew.l pts/27 82.24.39.119 10:29 29:22 0.54s 0.54s -bash
Jan 16 '08 #5

prn
Expert 100+
P: 254
prn
OK. I'll grant that you might have non-schoolwork reasons, but what you seem to be saying is that you are working through an on-line tutorial at the behest of your employers in order to learn unix. The difference is slight. The point is still to learn, so I'm not going to write very much for you.

I will make some suggestions, though. This is probably more than is best for your learning process, but here goes:

First, I'll say that I'd probably find this task a LOT easier to do in Perl than as a shell script. But is is possible to do it as a shell script -- just harder.

Try reading the man page for ps.Since you want all processes for all users, I'd start with
Expand|Select|Wrap|Line Numbers
  1. ps -e
which gives you process information for all users, but not identified by user. :-( Keep reading and you will find that you can specifiy the output format:
Expand|Select|Wrap|Line Numbers
  1. ps k user -eo user,pid,tty,time,cmd
gives you the format you want except that each line is preceded by the username of the relevant user. (I also skipped a step and sorted the output by user.)

Now, all you have to do is figure out how to strip off the username (man cut) from each line and output the real name (hint: check /etc/passwd) before each block of processes for the same username.

If you have specific questions, ask, but I think I've given you plenty of idea to get you going. I'm not going to write this for you. I'm just going to help you understand why specific things go wrong.

Regards,
Paul
Jan 17 '08 #6

P: 16
OK. I'll grant that you might have non-schoolwork reasons, but what you seem to be saying is that you are working through an on-line tutorial at the behest of your employers in order to learn unix. The difference is slight. The point is still to learn, so I'm not going to write very much for you.

I will make some suggestions, though. This is probably more than is best for your learning process, but here goes:

First, I'll say that I'd probably find this task a LOT easier to do in Perl than as a shell script. But is is possible to do it as a shell script -- just harder.

Try reading the man page for ps.Since you want all processes for all users, I'd start with
Expand|Select|Wrap|Line Numbers
  1. ps -e
which gives you process information for all users, but not identified by user. :-( Keep reading and you will find that you can specifiy the output format:
Expand|Select|Wrap|Line Numbers
  1. ps k user -eo user,pid,tty,time,cmd
gives you the format you want except that each line is preceded by the username of the relevant user. (I also skipped a step and sorted the output by user.)

Now, all you have to do is figure out how to strip off the username (man cut) from each line and output the real name (hint: check /etc/passwd) before each block of processes for the same username.

If you have specific questions, ask, but I think I've given you plenty of idea to get you going. I'm not going to write this for you. I'm just going to help you understand why specific things go wrong.

Regards,
Paul
Thanks very much Paul, thats the type of help i wanted. I'll get cracking on it and i'll pm you my answer sometime next week for your confirmation. Thanks again much appreciated.
Jan 17 '08 #7

prn
Expert 100+
P: 254
prn
Thanks very much Paul, thats the type of help i wanted. I'll get cracking on it and i'll pm you my answer sometime next week for your confirmation. Thanks again much appreciated.
Please do NOT PM me anything. The whole point of having forums is so that what we discuss here is available to everyone. That may not be your point, but it is close enough to mine that I will not discuss substantive forum topics in a PM. (If what you want to do is hire me as a consultant, that is a different matter. :-) )

Regards,
Paul
Jan 18 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.