Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

How to count users accessing to unix server

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
KG1973
Asked:
KG1973
  • 5
  • 3
  • 3
  • +3
2 Solutions
 
KG1973Author Commented:
I had used finger command, but it doesn't tell us the total number of users.
0
 
ozoCommented:
finger -l | grep '^Login:' | wc -l
0
 
woolmilkporcCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
woolmilkporcCommented:
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
 
woolmilkporcCommented:
... 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
 
TintinCommented:
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
 
KG1973Author Commented:
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
 
woolmilkporcCommented:
'who | cut -f1 -d" "  | grep gue2008  | sort | uniq | wc -l'

0
 
TintinCommented:
See my answer (iii.) that I've already provided.
0
 
KG1973Author Commented:
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
 
TintinCommented:
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
 
peter991Commented:
$> last | grep "still logged in" | awk '{print $1}' | grep gues2008 | sort -u | wc -l
0
 
SaranyakkaliCommented:
The best and simple is check with " last "command.. why cont i gve you that script?

Thanks
0
 
woolmilkporcCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now