473,516 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listing logged on users

16 New Member
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 2290
prn
254 Recognized Expert Contributor
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 Recognized Expert Moderator Specialist
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
thaiZilla
16 New Member
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
thaiZilla
16 New Member
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 Recognized Expert Contributor
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
thaiZilla
16 New Member
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 Recognized Expert Contributor
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
3245
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 current session. The problem is that the server does not know when the current session expires. (I have quite long timeouts.) Did anybody attempt...
12
2502
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 to store a logged in token. With only basic knowledge of sessions I assumed there was some kind of default time before the session data is...
8
1676
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 Application.Lock Application("ActiveUsers") = Application("ActiveUsers") + 1 Application.UnLock End Sub
8
3222
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 schedule the apps to start at 4:00 am, but at that time of night, nobody is logged on to the server. Is it possible to get Access to run on a...
2
1168
by: Patrick.O.Ige | last post by:
Whats the easiest way to list USERS that are logged on to ur site? Thx
8
3730
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 bool field to the table and set each user to 1 if they are logged in, and 0 if they are not logged in? *** Sent via Developersdex...
1
1993
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, companyID for example, so I'm using the profile feature to do this and it works great. Now the problem:
13
6710
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
2209
by: zy413952631 | last post by:
list the number of times each user is logged on Thank you for your kind concern
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.