Created
November 13, 2015 01:37
-
-
Save hiramhuang/2483951f83fc4329a072 to your computer and use it in GitHub Desktop.
Automatic create continuous user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $(id -u) -eq 0 ]; then | |
# as root user | |
read -p "Username prefix: " username | |
read -p "Password: " password | |
read -p "Group: " group | |
read -p "Quantity:" quantity | |
read -p "Shell: " login | |
grep -E "^$group" /etc/group > /dev/null | |
if [ $? -ne 0 ]; then | |
groupadd $group | |
echo "Group $group created." | |
fi | |
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) | |
current=0 | |
while [ $current -le "$quantity" ] | |
do | |
grep -E "^$username$current" /etc/passwd > /dev/null | |
if [ $? -eq 0 ]; then | |
echo "User $username$current is exists (Passed)" | |
current=$(($current+1)) | |
continue | |
fi | |
useradd -m -s $login -p $pass -g $group $username$current | |
echo "User $username$current has been created." | |
current=$(($current+1)) | |
done | |
[ $? -eq 0 ] && echo "All usr has been created!" || echo "Failed" | |
else | |
echo "Only allow root user to add user!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment