Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a way to display users logged on and there processes on one print rather than using "ps -a" and "finger" and then merging the relavent fields with AWK?
I can't seem to use the who -p option on my shell but I have found that if I type "ps -U" username then it lists the processes for that user, so If I can somehow extract the user names from who and then send then to "ps -U" one at a time then I should be okay, only trouble is I can't work out how to do it, it won't let me pipe the info.
I think I have it sorted, I need to find out how to make awk print " quotations marks, i tried preceding them with a backslash but it dont work, does anyone if its possible?
Mike
EDIT its okay, i got it sorted without them
I needed to write a program which displayed users and there processes plus there TTY and time and came up with this :
Code:
#!/bin/sh
finger > myfile
awk '{print $1, $2, $3}' myfile |
sed -e 's/Login Name Tty//g' |
awk '{print "echo " $2, $3} {print "ps -U ",$1} ' |
sed -e '1s/echo//g;2s/ps -U//g' > myfile
sh myfile
this works fine I now get
Code:
michael kelly
PID TTY TIME CMD
22339 ? 00:00:01 sshd
22340 pts/1 00:00:00 bash
30515 pts/1 00:00:00 sh
30521 pts/1 00:00:00 sh
30522 pts/1 00:00:00 ps
[michael.kelly@unix michael.kelly]$
What do you reckon? any ways I might look to improve it? I dont need the seconds sed commadn if I can stop awk's print method planting an extra echo and ps -U at the top of my script with no arguments beside them. I get an error but the rest of the scripts run so I ahev included the seconds sed to delete the lines before I call "sh" to execute.
A hint:
the problem you describe lies in the fact that the first line printed by "finger" is just a column header.
So, modify your first awk to disregard this header row and you should be fine.
A hint:
the problem you describe lies in the fact that the first line printed by "finger" is just a column header.
So, modify your first awk to disregard this header row and you should be fine.
Code:
awk '{print $1, $2, $3}' myfile |
thus should be replaced by:
Code:
awk {if (NR>1) print $1, $2, $3}' myfile |
or something like that.
Thanks, that sound good and will half the length of my script with adding 3 characters.
That also conculdes the course work I have to do so I won't be bothering you anymore (at least not for a while). I must say a big thank you to everyone who helped.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.