Merging Password Files

The first step is to create a merged /etc/passwd file. This involves several substeps:

  1. Physically merge the files, bringing duplicate usernames together. This becomes the input for the following steps.

  2. Split the merged file into three separate parts for use in later processing:

  • Users for whom the username and UID are the same go into one file, named unique1. Users with nonrepeated usernames also go into this file.

  • Users with the same username and different UIDs go into a second file, named dupusers.

  • Users with the same UID and different usernames go into a third file, named dupids.

  1. Create a list of all unique UID numbers that already are in use. This will be needed so that we can find new, unused UID numbers when a conflict occurs and we need to do a UID change (e.g., users jhancock and ben).

  2. Given the list of in-use UID numbers, write a separate program to find a new, unused UID number.

  3. Create a list of (username, old UID, new UID) triples to be used in creating final /etc/passwd entries, and more importantly, in generating commands to change the ownership of files in the filesystem.

    At the same time, create final password file entries for the users who originally had multiple UIDs and for UIDs that had multiple users.

  4. Create the final password file.

  5. Create the list of commands to change file ownership, and then run the commands. As will be seen, this has some aspects that require careful planning.

In passing, we note that all the code here operates under the assumption ...

Get Classic Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.