Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "==============================v2============================="
- echo " CJ'S USER AND GROUP CREATION TOOL"
- echo " Please keep your input limited to one argument"
- echo " - Run the script as root/sudo for guarenteed completion - "
- echo "================= PRESS ANY KEY TO CONTINUE ================="
- read -n 1 -s -p $'=============================================================\n'
- #Creating Username Variable
- echo ""
- echo -n "Desired Username: "
- read username
- #Checking that user input != nothing
- while [ "$username" = "" ];
- do
- echo ""
- echo "Username field cannot be empty."
- sleep 0.5
- echo -n "Please enter a username: "
- read username
- done
- #Checking if username already exists within the /etc/passwd file
- while grep -q -F $username /etc/passwd;
- do
- echo ""
- echo "Username already exists. Please try again."
- sleep 0.5
- echo -n "Desired Username: "
- read username
- while [ "$username" = "" ];
- do
- echo ""
- echo "Username field cannot be empty."
- sleep 0.5
- echo -n "Please enter a username: "
- read username
- done
- done
- echo ""
- echo -n "Desired Groupname: "
- read groupname
- #Checking if user enters nothing, therefore prompting the user to enter a groupname.
- while [ "$groupname" = "" ];
- do
- echo ""
- echo "Groupname field cannot be empty."
- sleep 0.5
- echo -n "Please enter a groupname: "
- read groupname
- done
- #Checking if groupname already exists within /etc/group file
- while grep -q -F $groupname /etc/group;
- do
- echo ""
- echo "Group already exists. Please try again."
- echo -n "Desired Groupname: "
- read groupname
- while [ "$username" = "" ];
- do
- echo ""
- echo "Groupname field cannot be empty."
- echo -n "Please enter a groupname: "
- read username
- done
- done
- echo ""
- echo -n "Desired Password: "
- read -s password
- #Litle bit of code that sends message if the password is less than 5 chars long
- while [ ${#password} -lt 5 ];
- do
- echo ""
- echo "Your password must contain 5+ characters"
- sleep 0.2
- echo "Please try again."
- sleep 0.5
- echo ""
- echo -n "Desired Password: "
- read -s password
- done
- echo ""
- sleep 1
- read -p "Initialize user/group creation? (Y/N)" yn
- case $yn in
- [Yy]* ) ;;
- [Nn]* ) exit;;
- * ) echo "Please answer yes or no.";;
- esac
- #Creating the user and group and adding the user to the group
- sudo useradd $username
- sudo groupadd $groupname
- echo $username:$password | sudo chpasswd
- sudo adduser $username $groupname
- sleep 1
- echo "No errors = Successful"
- sleep 0.2
- echo "Thank you for using the tool!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement