Personal tools
You are here: Home Unix Network and Scripts userclone
Document Actions

userclone

by admin last modified 2010-03-30 22:08

Mit Befehlen wie groupadd und useradd werden neue Gruppen und Benutzer angelegt. Einen Befehl, um User mit all Ihren Daten wie $HOME, der shell oder der PID unkompliziert auf einem anderen System nachzubilden, fehlte bisher. Diese Lücke schliesst userclone!

#!/bin/sh

#Check a named account and create commands to create this account
#usage: userclone <username>
# (C) Michael Renner <michael.renner@dab.com>

PASSWD=`grep $1 /etc/passwd`
SHADOW=`grep $1 /etc/shadow`

# the username
P1=`echo $PASSWD | cut -d ":" -f1`

if [ "$1" != "$P1" ] ; then
echo "found an error"
echo "looking for $1, but found $P1"
exit 65
fi

# the password
P2=`echo $PASSWD | cut -d ":" -f2`
if [ "$P2" = "x" ] ; then
# check the password in /etc/shadow
P2=`echo $SHADOW | cut -d ":" -f2`
X=shadow
else
X=passwd
fi

# UID, GUI, HOME, comments and shell
P3=`echo $PASSWD | cut -d ":" -f3` # username
P4=`echo $PASSWD | cut -d ":" -f4`
P5=`echo $PASSWD | cut -d ":" -f5`
P6=`echo $PASSWD | cut -d ":" -f6`
P7=`echo $PASSWD | cut -d ":" -f7`

# find out the group name
GROUP=`id -p $P3 | cut -d "(" -f3 | cut -d ")" -f1`
# and now the commands
echo "if [ \"\`grep $GROUP /etc/group | cut -d \":\" -f3\`\" != \"$P4\" ] ; then groupadd -g $P4 $GROUP ; fi "
echo "/usr/sbin/useradd -u $P3 -g $P4 -d $P6 -c \"$P5\" $P1"
echo "/usr/bin/mkdir -p $P6 && chown $P1:$P4 $P6"
echo "cp /etc/$X /tmp/$X~ ; cat /etc/$X | sed s@$P1:.LK.@$P1:$P2@ > /tmp/$X && mv /tmp/$X /etc/$X"



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: