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!!
Unix OS

Avatar of undefined
Last Comment
evilrix
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.

Avatar of Mrdogkick
Mrdogkick

ASKER

any luck??
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

It is not easy and requires time :)

do you expect to have the same user logged in from more than one terminal?
Avatar of Mrdogkick
Mrdogkick

ASKER

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.
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

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
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> I am not supposed to use awk.
Hmmm, this make this somewhat harder! Why can't you use awk?
Avatar of Mrdogkick
Mrdogkick

ASKER

Thats just one of the requirements...
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

requirement? Is this homework? If so you should have stated that fact!
Avatar of Mrdogkick
Mrdogkick

ASKER

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?
Avatar of Mrdogkick
Mrdogkick

ASKER

not homework, just an exercise

Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> 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.
Avatar of Mrdogkick
Mrdogkick

ASKER

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.
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> 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.
Avatar of Mrdogkick
Mrdogkick

ASKER

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.
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Ok,  fair enough.

-Rx.
Unix OS
Unix OS

Unix is a multitasking, multi-user computer operating system originally developed in 1969 at Bell Labs. Today, it is a modern OS with many commercial flavors and licensees, including FreeBSD, Hewlett-Packard’s UX, IBM AIX and Apple Mac OS-X. Apart from its command-line interface, most UNIX variations support the standardized X Window System for GUIs, with the exception of the Mac OS, which uses a proprietary system.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo