useradd ½ºÅ©¸³Æ®
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2006-04-25 00:33:04
 

#!/bin/ksh
#

cat << EOF
Adduser Korn Shell Script for Solaris 2.x


EOF

# Test if running as root or die
x=`id | grep root`
[ -z "$x" -a -n "$1" ] && $1 "${PROGNAME}: Must run as ROOT" && qdie

Checkuids()
{


low=2000
high=2999
prev=$((low-1))
found=n

awk -F: '$3>=2000&&$3<=2999{print $3}' /etc/passwd |
sort -un |
while read uid junk; do
#...don't do any more testing if one has been found
if [[ $found = "n" ]]; then
prev=$((prev+1))
if (( prev != uid )); then
found=y
UNUSED=$prev
fi
fi
done

#...but what happens if nothing was found

if [[ $found = "n" ]]; then

if (( prev == low-1 )); then
UNUSED=$low
else
if (( prev >= high )); then
echo $errorstring
exit 1
else
prev=$((prev+1))
UNUSED=$prev
fi
fi
fi
}

echo -n "Username: "
read USERNAME
[ -z "$USERNAME" ] && exit 2

echo -n "Realname: "
read REALNAME
[ -z "$REALNAME" ] && exit 2

Checkuids
echo "Next unused uid = $UNUSED"
echo -n "UID [$UNUSED]: "
read UID
[ -z "$UID" ] && UID=$UNUSED

GIDDEFAULT=10
echo -n "GID [$GIDDEFAULT]: "
read GID
[ -z "$GID" ] && GID=$GIDDEFAULT

#echo -n "Enter Password: "
#stty -echo
#read PASSWORD
#stty echo
#[ -z "$PASSWORD" ] && exit 2

# Chose defaults... you can't change 'em (yet)
HOMEDIR="/usr/home/"$USERNAME
SHELL="/bin/csh"

echo "Homedir is $HOMEDIR"
echo "Shell is $SHELL"

echo -n "Adding user..."
/usr/sbin/useradd -c "$REALNAME" -d "$HOMEDIR" -g "$GID" -m -k /etc/skel -u "$UID" -s "$SHELL" $USERNAME
echo "Done."
/usr/bin/passwd $USERNAME
#expire the password
/usr/bin/passwd -f $USERNAME
echo "Password reqired to be changed at next login."


¸ñ·Ï | ÀÔ·Â | ¼öÁ¤ | ´äº¯ | »èÁ¦