473,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Listing logged on users

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
7 2285
prn
254 Expert 100+
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
3,509 Expert Mod 2GB
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
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
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
254 Expert 100+
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
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
254 Expert 100+
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

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

Similar topics

4
by: vesely | last post by:
Hi all, I'm currently relying on logged-in users hitting "logout" (logoff) before they leave, in order to terminate the session. With PHP the session filename is in a cookie that lasts for the...
12
by: Dave Smithz | last post by:
Hi there, Users of my PHP DB application have complained that it seems to log them out every now and then. I actually assume this is when it has been idle for sometime as I use session variables...
8
by: gil | last post by:
I'm trying to track how many users are visiting a site and how may are logged in, using application sessions like so: Sub Session_OnStart Session.Timeout = 20 Session("Start") = Now...
8
by: Mike Thomas | last post by:
I have two clients now who want to have an Access 2000 & 2002 application running on NT Server 2000 do some file updating at night when nobody is in the office. I have used Windows scheduler to...
2
by: Patrick.O.Ige | last post by:
Whats the easiest way to list USERS that are logged on to ur site? Thx
8
by: Mike P | last post by:
What would be the best way of counting the number of users who are currently logged on to a website? I am making the users login against a database of valid users. Would the best way be to add a...
1
by: kpg* | last post by:
Hi all, Trying to use the ASP.NET 2.0 membeship API to manage users and user profiles, and of course, to provide role based security to my web app. I have several attributes I want to users,...
13
by: snowinfo | last post by:
Hi all, any way to count the number of users i have logged into my site? any help/code appreciated, craig
1
by: zy413952631 | last post by:
list the number of times each user is logged on Thank you for your kind concern
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.