Link to home
Start Free TrialLog in
Avatar of Mrdogkick
Mrdogkick

asked on

processes etc....

I use who to check users currently logged on to the system. the format is as follows...

milade.makram pts/15       2007-12-07 09:54 (172.16.1.73)

say I want to cut into this and display it as follows (NB the tty and time headers):

Makram Milade
TTY       Time
pts/15   09:54

so effectively it would put the second word first, then the 1st, thus making the users full name in the right order. Then it would print the processes under their respective headings just below. Any help would be great!!
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Try

set milade.makram pts/15       2007-12-07 09:54 (172.16.1.73)
echo $1 | awk -F"." '{print $2 " " $1}'
echo "TTY       Time"
echo $2 $3
Avatar of Mrdogkick
Mrdogkick

ASKER

sorry, I should have been a bit more clear...

1. I am not supposed to use awk.
2. I need it to show all of the users logged on in that format, not just 1.

any luck??
It is not easy and requires time :)

do you expect to have the same user logged in from more than one terminal?
ill be a bit more clear...

I am to create a script which will allow you to find all users currently logged on to the system and display the processes they are running. The heading for each user must be their real name not their log in name.
I.e. my login name is milade.makram but my real name is Makram Milade
The users must not be displayed more than once.
The output should look similar to this.

Makram Milade
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

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

Write the output to a file.
Ok,

I have provided a solution for what you are asking for a previous case.

I will refer you to the solution, but you need to use awk.

https://www.experts-exchange.com/questions/23000179/script-to-print-all-users-looged-in-the-system-and-their-processes-should-display-real-name-on-the-top-then-their-processes-for-each-user.html
>> I am not supposed to use awk.
Hmmm, this make this somewhat harder! Why can't you use awk?
Thats just one of the requirements...
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
requirement? Is this homework? If so you should have stated that fact!
yeah, like I said they wont accept it....Is there no way to do it in a similar way to the question u answered for me before? ie read all the users curently logged then cut from that the required fields?
not homework, just an exercise

>> yeah, like I said they wont accept it....
It was disingenuous of you to not declare this was homework! EE rules are clear, now that I am aware this is homework I cannot provide you with full code examples. I suggest you take what I've provided you so far and then look at how to change it to use cut or maybe even Perl.

>> Is there no way to do it in a similar way to the question u answered for me before? ie read all the users curently logged then cut from that the required fields?
Had I know these were homework questions I would not have provide you with any code!

https://www.experts-exchange.com/help.jsp#hi105

I am afraid I can provide you no further code examples. You need to work with what you already have.
Im sorry that you feel that way, but like I said, its not homework, it's some exercises that I am trying to work through as I have noticed that a lot of the jobs I am applying for require a bit of Unix knowledge and that is something that they didn't cover during my degree. Thanks for your help anyways.
>> Im sorry that you feel that way, but like I said, its not homework,

Q. Is this homework? If so you should have stated that fact!
A. yeah, like I said they wont accept it

Your answer clearly implies this is a homework question. I am not being awkward, I am unable to provide code samples as I am bound, like you, bu EE rules. If I knowingly provide code to a homework related question I and you could have our accounts terminated! The answer I have provided above should give you a good head-start, but it'll be a good exercise for you to try and modify it to not use awk.

-Rx.
I fully understand this and appreciate your help but It is not homework and by 'they' i meant the book where I am getting the exercise from, not a teacher and that answer was to the post before the one you are looking at. Again a case of me replying before refreshing. I guess this can lead to misunderstandings. Anyways, thanks again for the help.
Ok,  fair enough.

-Rx.