We help IT Professionals succeed at work.

processes etc....

Mrdogkick
Mrdogkick asked
on
263 Views
Last Modified: 2010-04-21
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!!
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
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

Author

Commented:
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.

Author

Commented:
any luck??
CERTIFIED EXPERT
Top Expert 2007

Commented:
It is not easy and requires time :)

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

Author

Commented:
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.
CERTIFIED EXPERT
Top Expert 2007

Commented:
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/Programming/Languages/Scripting/Shell/Q_23000179.html
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

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

Author

Commented:
Thats just one of the requirements...
Senior Software Engineer (Avast)
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
requirement? Is this homework? If so you should have stated that fact!

Author

Commented:
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?

Author

Commented:
not homework, just an exercise

evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
>> 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.

Author

Commented:
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.
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
>> 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.

Author

Commented:
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.
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
Ok,  fair enough.

-Rx.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.