Solved

How to count users accessing to unix server

Posted on 2008-11-02
14
431 Views
Last Modified: 2013-12-27
I want to count how many users accessing our unix server.

The unix command should do the following :
i. list all users logged in to the server
ii. list of all users that their id , letsay any user id that has trailing id with "gues2008"
iii. simply count total users in (ii), but no duplication, ie, if there are more than one session user A had accessed, thenit shold considered as one.
iv. if possible , from the list (ii) can differentiate local access or remote access.

Thanks.
0
Comment
Question by:KG1973
  • 5
  • 3
  • 3
  • +3
14 Comments
 
LVL 1

Author Comment

by:KG1973
ID: 22862342
I had used finger command, but it doesn't tell us the total number of users.
0
 
LVL 84

Expert Comment

by:ozo
ID: 22862370
finger -l | grep '^Login:' | wc -l
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22862452
Hi,
1.)   'who'
2.) ???
3.) 'who | cut -f1 -d" " | sort | uniq | wc -l'

4.Look at the 4th column of 'who' output. You'll see there the hostnames (or addresses) the users come from.
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22862479
Hi again,

try this one, perhaps its a step towards the answer to question 'ii' :

 lsuser -a gecos $(echo $(who | cut -f1 -d" " |sort | uniq) | tr " " ",")


0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22862508
... and in case you don't like the 'gecos=' stuff, please:

 lsuser -a gecos $(echo $(who | cut -f1 -d" " |sort | uniq) | tr " " ",") | sed "s/gecos=//"
0
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 22863231
i.   w
ii.  w | grep gue2008
iii.  who  |  awk '/gues2008/ {print $1}' | sort -u | wc -l
iv. Depends what you mean by 'local'.  Local as in from your network?  Directly connected to the server?
0
 
LVL 1

Author Comment

by:KG1973
ID: 22863528
Hence  the following users logged in to the system :
ABCgue2008
ABCgue2008
HIJgue2008
KLMgue2008
MNOgue2008
PQRgue2008
STUgue2008

if I type this command,  who | grep 'gue2008' | wc -l
This will give the total count of 7. But I don't want to count double entries ( ABCgue2008 ).
Thus the output should be 6.

So what cmd or flag should  I use ?
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 100 total points
ID: 22863536
'who | cut -f1 -d" "  | grep gue2008  | sort | uniq | wc -l'

0
 
LVL 48

Expert Comment

by:Tintin
ID: 22863559
See my answer (iii.) that I've already provided.
0
 
LVL 1

Author Comment

by:KG1973
ID: 22863981
Tintin,
Sorry I missed some flags, thats why it is not working when i try earlier.
Now I am repeating it again, It work. Thanks.
Can you explain what the argument " awk '/gues2008/ {print $1} '" do actually,  mean 1 by 1.
awk ?
{print $1} ?

Also i found that i can also use finger instead of who. Is there any distinctive diff ?

0
 
LVL 48

Expert Comment

by:Tintin
ID: 22864824
The /gues2008/ mean match any line that contains the string 'gues2008'.

print $1 means print the first field (in this case, the user column)
0
 
LVL 6

Expert Comment

by:peter991
ID: 22866013
$> last | grep "still logged in" | awk '{print $1}' | grep gues2008 | sort -u | wc -l
0
 
LVL 3

Expert Comment

by:Saranyakkali
ID: 22867135
The best and simple is check with " last "command.. why cont i gve you that script?

Thanks
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22867220
Hi,
the problem with 'last' is, when you do some pruning/shortening/archiving of your wtmp file, you will loose the records of users who have logged in a longer time ago and are still logged in.
wmp
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 94
to update from RHEL 6.0 to 6.8 anything needed other than "yum update"? 7 101
mobaxterm not able to change directory 28 148
awk sed 8 42
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question