*****************************************
* Linux User Manager *
* 1. Create User *
* 2. Delete User *
* 3. Update Password *
* 4. Add user to group *
*****************************************
#vi /shell/userma
#!/bin/bash
menu() {
clear
echo "*****************************************"
echo "* Linux User Manager *"
echo "* 1. Create User *"
echo "* 2. Delete User *"
echo "* 3. Update Password *"
echo "* 4. Add user to group *"
echo "*****************************************"
}
cu() {
while [ 1 -lt 2 ]
do
echo -n "username:"
read u
if [ -z $u ]
then
echo "username error"
continue
fi
if grep -q "^$u:" /etc/passwd
then
echo "user $u exists"
contiune
fi
useradd $u
break
done
}
du() {
echo -n "username:"
read u
if grep -q "^$u:" /etc/passwd
then
userdel $u
else
echo "user $u is not exists"
fi
}
echo -n "username:"
read u
if grep -q "^$u:" /etc/passwd
then
passwd $u
else
echo "user $u is not exists"
fi
}
ag() {
echo -n "username:"
read u
echo -n "groupname:"
read g
if grep -q "^$u:" /etc/passwd
then
if grep -q "$g:" /etc/group
then
gpasswd -a $u $g
fi
fi
}
menu
echo -n "please input choice:"
read c
case $c in
1)
cu
;;
2)
du
;;
3)
up
;;
4)
ag
;;
*)
echo "please input 1-4"
;;
esac
















