0

I need help in writing Bourne / BASH script that determines the number of potential users for the system by getting a count of the number of passwords contained in the system's password file.

I tried /etc/passwd. It always comes up saying "Permission Denied". I change myself as a root user, same problem there as well. I am not able to figure out how to do it.

3
  • 1
    As root, you should be able to read /etc/passwd
    – Tom Fenech
    Nov 13, 2013 at 11:05
  • Show your script! /etc/passwd should be word readable. getent passwd should also list potential users passwd lines. Nov 13, 2013 at 11:06
  • 1
    Even as non-root it should be readable. Sth else is going wrong here.
    – Alfe
    Nov 13, 2013 at 11:07

2 Answers 2

0

Assuming your non-system user accounts start numbering at 500:

getent passwd | awk -F':' '{ if ($3 >= 500) print $1}'

And if they start at 1000:

getent passwd | awk -F':' '{ if ($3 >= 1000) print $1}'

Next:

  1. Count the number of high-id "nobody" accounts (e.g., "nfsnobody"). This is any users returned from the above commands that look like they're dummy accounts.

  2. Append | wc -l to the command used from above and subtract the count from step 1.

This should provide the number of non-system accounts (e.g., "potential" users) on the system.

0

The file /etc/passwd normally isn't read-protected for normal users, so you need to investigate why this is the case on your system. But even if you can read it, it will contain lots of technical users (like lp, syslog, bin, daemon, etc.); I'm not sure you want to include those. To filter these out you would need a list of names of known technical users, e. g.:

egrep -v '^(daemon|bin|sys|sync|games|man|lp|mail|news|uucp|proxy|nobody|syslog)' /etc/passwd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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