#!/bin/bash
if [ "$1" = "create" ]
then
if [ -z "$2" ]
then
echo please give me a userfile
elif [ ! -e "$2" ]
then
echo "$2 is not exist!!"
else
for NAME in `cat $2`
do
USER=`getent passwd $NAME`
if [ -z "$USER" ]
then
useradd $NAME
echo westos | passwd --stdin $NAME
else
echo $NAME is exist!!
fi
done
fi
elif [ "$1" = "delete" ]
then
if [ -z "$2" ]
then
echo please give me a userfile
elif [ ! -e "$2" ]
then
echo "$2 is not exist!!"
else
for NAME in `cat $2`
do
USER=`getent passwd $NAME`
if [ -n "$USER" ]
then
userdel -r $NAME
else
echo $NAME is not exist!!
fi
done
fi
else
echo "Useage: ctrl_user.sh <create|delete> <userfile>"
fi
if [ "$1" = "create" ]
then
if [ -z "$2" ]
then
echo please give me a userfile
elif [ ! -e "$2" ]
then
echo "$2 is not exist!!"
else
for NAME in `cat $2`
do
USER=`getent passwd $NAME`
if [ -z "$USER" ]
then
useradd $NAME
echo westos | passwd --stdin $NAME
else
echo $NAME is exist!!
fi
done
fi
elif [ "$1" = "delete" ]
then
if [ -z "$2" ]
then
echo please give me a userfile
elif [ ! -e "$2" ]
then
echo "$2 is not exist!!"
else
for NAME in `cat $2`
do
USER=`getent passwd $NAME`
if [ -n "$USER" ]
then
userdel -r $NAME
else
echo $NAME is not exist!!
fi
done
fi
else
echo "Useage: ctrl_user.sh <create|delete> <userfile>"
fi