-6

I want to know How to determine current users who are logged in using a specific domain?

For example, here is the question. Please tell according to it using the grep command and use of wc.

Question: Write a C shell script called countkpu which determines how many of the currently logged in users are logged in from a computer on the kwantlen.ca domain.

To do this, note the who command will show each user who is logged in along with identification of their computer.

You can feed this information to the grep command, to only display strings that contain the "kwantlen.ca". You can then further feed this output to the wc command, which can be used in such a way to just count lines of output.

HERE IS WHAT I DID:

grep `hostname` /etc/hosts  

results:

10.65.36.35    gator    gator.kwantlen.ca   loghost  

The Problem is how will I combine the who command as in the question? I mean it is not telling who is logged in using this domain.

closed as off-topic by Gilles, Stephen Harris, G-Man, Networker, jsbillings Jul 17 '16 at 11:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Stephen Harris, Networker, jsbillings
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Please edit your question rather than reposting it. And don't use new accounts to bypass question rate limits, using multiple accounts to evade system restrictions is not allowed. – Gilles Jul 16 '16 at 23:16
  • @Gilles What do you want me to edit it now? I think by posting the question (IN TEXT) I can best explain you. Hope you understand and I respect StackExchange policy. Can you please help me? – user180074 Jul 16 '16 at 23:20
  • 1
    @Fred: I'm sure if you paid a little bit more attention to your course, you could get it done in 10 minutes. If you show us a good effort in solving it yourself, we could certainly help you. – Julie Pelletier Jul 16 '16 at 23:36
  • @JuliePelletier thanks. I have written what I did. Please can you help me? – user180074 Jul 16 '16 at 23:43
  • 4
    Why are people still teaching C-shell? – glenn jackman Jul 17 '16 at 1:15
0

The question nearly gives it away, if you're familiar with pipes:

To do this, note the who command will show each user who is logged in along with identification of their computer.

You can feed this information to the grep command, to only display strings that contain the "kwantlen.ca". You can then further feed this output to the wc command, which can be used in such a way to just count lines of output.

The answer they're probably looking for, in a form usable by either csh or bash or zsh or ksh:

who | grep kwantlen.ca | wc -l

or, to golf it shorter:

who | grep -c kwantlen.ca

References:

  • Yes first I did like this, but here is my confusion, you know when we give a command who it display all the users using the UNIX. In my case, I can see the users but there is not text like "kwantlen.ca" ; I can see their IP address , usernames, but where is kwantlen.ca ? It never displays!! so ultimately your command also does the same thing like what I did before posting this question that is nothing gets appeared. What do you think if kwantlen.ca never gets appeared in who command then what is our instructor mean? – Zeus Jul 17 '16 at 2:37
  • Apparently they are logged in from somewhere else! 0 might be the right answer in that case. Or maybe the IPs aren't getting resolved to names. – Jeff Schaller Jul 17 '16 at 2:41
  • yes I think IP address aren't resolved to names, you know how ? let's suppose I'm at home I know my IP address will be assigned by my internet service provider and its for example telus.net, but the person I can see right now he is in Kwantlen Polytechnic University and using the gator from there, but his IP address is also some numbers eg. 452. 234. 234. 454 instead of @kwantlen.net at the end which should be because he is in University. Do you have a solution for resolving to names ? – Zeus Jul 17 '16 at 2:46
  • I don't. I suspect you have the answer the teacher wants. – Jeff Schaller Jul 17 '16 at 3:04
  • Yup! I think so this would be an answer and teacher is just trying to trick us and it wasted so much my time. Anyways, thanks! – Zeus Jul 17 '16 at 3:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.