I am trying to determine if the passwd file present in the location /etc/passwd in Linux contains any invalid data entries with the pwck command.
For example:
1) If my file contains this entry which is invalid due to the extra colon in the end - user1:x:1000:1000:user1,,,:/home/user1:/bin/bash:
sudo pwck -r /etc/passwd
This takes a no by default if invalid entries exist and shows other output as well
2) If my passwd file is correct syntactically but has user that does not have corresponding directories
sudo pwck -r /etc/passwd
user 'user1': directory '/var/xyz' does not exist
The exit values of both commands is 2 so I cannot distinguish if the user entry is invalid or there are directories for users that are non existent
I only want to identify an invalid entry in passwd file i.e if there is some extra character or syntactically wrongly added entry in the file
If you want only the "syntatic" correctness, just write a regex to match it. Reading from wikipedia and shadow sources to match the user name right, I wrote this for GNU sed:
But there are many other checks that
pwckdoes.So I think the best way would be to take
pwcksources and hand-pick the checks you are interested in and remove the checks you are not interested in.Sure you can distinguish - as the program outputs what is wrong with the file.