October 30, 2015

useradd script fail

Im getting a tr: [:upper:] and/or [:lower:] misalignment and I'm not sure why. Also on the useradd line it's erroring saying group -G doesnt exist when -G is an addition group option not a group......Help

# Name: script1
# Version: 1.0
# Purpose: To add users to system and groups
# Created: 10-29-2015
# Creator: Matt Winnekins

echo "Enter users FIRST name"
read FNAME

echo "Enter LAST name"
read LNAME

echo "Enter the users INITIAL group"
read IGROUP

echo "Enter the users ADDITIONAL groups"
read AGROUP

# Now trim the output

DNFNAME=`echo $FNAME | tr [:upper:] [:lower:]`
DNLNAME=`echo $LNAME | tr [:upper:] [:lower:]`

LOWIGROUP=`echo $IGROUP | tr [:upper:[ [:lower:]`
LOWAGROUP=`echo $AGROUP | tr [:upper:] [:lower:]`

UFNAME=`echo $FNAME | tr [:lower:] [:upper:] | cut -c 1`
DFNAME=`echo $DNFNAME | cut -c 2-`

ULNAME=`echo $LNAME | tr [:lower:] [:upper:] | cut -c 1`
DLNAME=`echo $DNLNAME | cut -c 2-`

CFFNAME=`echo $UFNAME$DFNAME`
CFLNAME=`echo $ULNAME$DLNAME`

LOGIN=`echo $DNLNAME$DNFNAME`
useradd -c "$CFLNAME, $CFFNAME" -g $LOWIGROUP -G $LOWAGROUP $LOGIN
echo 123456 | passwd --stdin $LOGIN

# repeat script below

echo "Press (y) to add another user"
read YORN

CLEANYORN=`echo $YORN | cut -c 1 | tr [:upper:] [:lower:]`

if [ "CLEANYORN" = "y" ] ; then

./script1

fi

Click Here!