Created
January 27, 2015 21:23
-
-
Save briantissue/1c8b15c80d472c41ffa6 to your computer and use it in GitHub Desktop.
Migrate Linux UIDs and GIDS to new box excluded system IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This shell script is moving uids and gids to new server without grabbing the system accounts | |
#The one caveat with this script is confirming the UID start limit and upper limit for your distro | |
#This can be confirmed by checking the /etc/libuser.conf it is denoted there in RHEL distros | |
#This script is to be ran from the /tmp directory as denoted in BASE | |
#This script is valid for 6.5 RHEL and down as is. Change UGIDLIMIT to 1000 for v7.0 | |
#Create directory for migration files | |
BASE=/tmp | |
if [ -d ${BASE}/move ] | |
then | |
echo “The move directory exists.” | |
else | |
echo “Creating the move directory.” | |
mkdir ${BASE}/move | |
fi | |
#Setup UID filter limit to setup UID start limit for normal user account. | |
#RHEL/CentOS/Fedora Core : Default is 500 and upper limit is 65534 /etc/libuser.conf | |
#This should filter out the system accounts | |
export UGIDLIMIT=500 | |
#Now copy /etc/passwd accounts to /tmp/move/passwd.mig using awk to filter out system account i.e. only copy user accounts | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' ${BASE}/passwd > ${BASE}/move/passwd.mig | |
#Copy /etc/group file | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' ${BASE}/group > ${BASE}/move/group.mig | |
#Copy Shadow File | |
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' ${BASE}/passwd | tee - |egrep -f - ${BASE}/shadow > ${BASE}/move/shadow.mig | |
#Append the files in etc from the filtering above on new server | |
#cat ${BASE}/move/passwd.mig >> /etc/passwd | |
#cat ${BASE}/move/group.mig >> /etc/group | |
#cat ${BASE}/move/shadow.mig >> /etc/shadow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment