Migrate Users

From Noah.org
Revision as of 03:27, 4 November 2009 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Migrate Users From Old Linux box to new Linux box

#!/bin/sh

#
# This script helps migrate user accounts to a new server.
#

IDMIN=1000
IDMAX=29999
DESTDIR=/root/migrate

if [ $(id -u) -ne 0 ]; then 
    echo "You must be root to run this."
fi

mkdir -p ${DESTDIR}
cd /etc
awk -v VIDMIN=${IDMIN} -v VIDMAX=${IDMAX} -F: '($3>=VIDMIN) && ($3!=VIDMAX)' passwd > ${DESTDIR}/passwd.old
awk -v VIDMIN=${IDMIN} -v VIDMAX=${IDMAX} -F: '($3>=VIDMIN) && ($3!=VIDMAX)' group > ${DESTDIR}/group.old
awk -v VIDMIN=${IDMIN} -v VIDMAX=${IDMAX} -F: '($3>=VIDMIN) && ($3!=VIDMAX) {print $1}' passwd | tee - | egrep -f - shadow > ${DESTDIR}/shadow.old
cp /etc/gshadow ${DESTDIR}/gshadow.old
cp /etc/sudoers ${DESTDIR}/sudoers.old
tar czf ${DESTDIR}/etc.tar.gz ${DESTDIR}/*.old
#tar czpf ${DESTDIR}/home.tar.gz /home
echo "WARNING! Not including /home in the migration."

# vim:set sr et ts=4 sw=4 ft=sh: // See Vim, :help 'modeline'