Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Challenge 3 - Bash Script Development
- #
- #
- # Change Log:
- # 13/11/18 - BW - Created initial file
- # 13/11/18 - BW - Added Code to read input, check and create group
- # Ask user for input
- # Use getent group to query the group database,
- # pipe the input to grep (with the query of input group)
- #
- # If grep returns a line, the group exists
- # if grep does not return a line, the group does not exist
- GROUP_CREATED=0 # loop control variable
- while [ $GROUP_CREATED -eq 0 ]
- do
- echo "Please enter the new group name: "
- read INPUT_GROUP
- if getent group $INPUT_GROUP | grep -q $INPUT_GROUP ; then
- echo "The group ' $INPUT_GROUP ' already exists. Try again"
- else
- echo "The group ' $INPUT_GROUP ' doesn't currently exist"
- groupadd $INPUT_GROUP
- echo "The group ' $INPUT_GROUP ' has now been added"
- GROUP_CREATED=1 #set loop control flag
- #we probably should do some error checking on that
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement