Operating System - HP-UX
1836529 Members
3644 Online
110101 Solutions
New Discussion

Re: Merge /etc/passwd between two servers removing sys accounts

 
Romanek
Advisor

Merge /etc/passwd between two servers removing sys accounts

Hello All,

I have two rp3440 running 11.11 in a clustered environment. I'm look to merge the two /etc/passwd files. The only issue is that I need to remove all system accounts (i.e. root, bin, sys,) So that I don’t have duplicate accounts. The way I have the two server setup is that so all users on serverA UID falls between 1000 – 2999 and all users on serverB UID’s fall between 3000 – 4999. I would like to just remove all entries in /etc/passwd with a UID lower that 1000 on serverA. I would also like to script this process. I was looking I was looking at doing a sort on the file first but kind of lost after that. Any help is much appreciated.

-Paul
You can have my UNIX server when you pry it from my cold dead fingers
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: Merge /etc/passwd between two servers removing sys accounts

This should get you started:

---------------------------
#!/usr/bin/sh


INFILE=/etc/passwd

awk -F ':' '{ if (($3 + 0) >= 101) {print $0}}' ${INFILE}

This will read /etc/passwd and output on stdout all lines where UID (field 3) is >= 101 -- ie, it will exclude all of the system accounts. The ($3 + 0) is intentional if seemingly nonsensical because it forces the evaluation into a numeric rather than a string context.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Merge /etc/passwd between two servers removing sys accounts

Hi Paul:

As far as culling accounts you can simply do something like:

# awk -F: '$3>=1000 && $3<= 2999' /etc/passwd > /tmp/passwd.serverA

The resulting file could be concatenated with the file from ServerB assuming that there are no duplicate login names.

Regards!

...JRF...