Hey, I'm running an HP-UX box, trying to create a little script that will compare the /etc/passwd file with another file I have created.
Each line in this file, let's call it /etc/myusers, has a pin that the user has chosen (not necessarily unique), then their userid, then the comments field from /etc/passwd. (basically their full name, phone number, all that jazz.
Here is an example:
pin:userid:comments:
1234:pittb:"Brad Pitt,Los Angeles CA,123-123-1234":
9876:clooneyg:"George Clooney,Los Angeles CA,123-123-1234":
6548:dansont:"Ted Danson,Los Angeles CA,123-123-1234":
9685:owenc:"Clive Owen,Los Angeles CA,123-123-1234":
1652:simpsonh:"Homer Simpson,Los Angeles CA,123-123-1234":
I basically want to make sure that every account in my /etc/passwd file is also in this file. So all I want to do is go through each line in /etc/passwd, and search for each userid in this custom file. If the name DOESN'T exist, I want to print it out, to the screen, or a file, or whatever, so I can go through and add all the accounts to this file.
It should be fairly simple, I just can't quite figure it out.
I was thinking of just doing an awk on the /etc/passwd file and pulling out all the usernames to a file, and then doing a for loop through that file, or something like this:
root# awk -F: '{ print $1 }' /etc/passwd > users.txt
root# for x in `cat users.txt` ; do
>grep $x /etc/myusers
>if no result, print to file or whatever...?
Just not quite sure what.
Thanks for your help.