Merge pull request #115 from Codehunter-py/improvement_create-user
added userdel command in Linux/create-user.sh script
This commit is contained in:
commit
ec2122f449
32
Days/Linux/create-user.sh
Normal file → Executable file
32
Days/Linux/create-user.sh
Normal file → Executable file
@ -1,15 +1,27 @@
|
|||||||
#! /usr/bin/bash
|
#! /usr/bin/bash
|
||||||
|
if [ -z "${1}" ]
|
||||||
|
then
|
||||||
|
echo "What is your intended username?"
|
||||||
|
read username
|
||||||
|
echo "What is your password"
|
||||||
|
read password
|
||||||
|
|
||||||
echo "What is your intended username?"
|
#A user can be passed in as a command line argument
|
||||||
read username
|
echo "$username user account being created."
|
||||||
echo "What is your password"
|
|
||||||
read password
|
|
||||||
|
|
||||||
#A user can be passed in as a command line argument
|
#A user is created with the name of command line argument
|
||||||
echo "$username user account being created."
|
sudo useradd -m $username
|
||||||
|
|
||||||
#A user is created with the name of command line argument
|
#A password can be parsed in as a command line argument.
|
||||||
sudo useradd -m $username
|
sudo chpasswd <<< $username:$password
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
echo "If you want to delete the user then pass 'del' and username in command line argument. e.g: ./create-user.sh del username"
|
||||||
|
|
||||||
|
else
|
||||||
|
sudo userdel -rf "${2}"
|
||||||
|
sleep 2
|
||||||
|
echo "${2} user account successfully deleted."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
#A password can be parsed in as a command line argument.
|
|
||||||
sudo chpasswd <<< $username:$password
|
|
@ -152,7 +152,7 @@ We might also use bash scripting to determine information about files and folder
|
|||||||
- `-d file` True if the file is a directory
|
- `-d file` True if the file is a directory
|
||||||
- `-e file` True if the file exists
|
- `-e file` True if the file exists
|
||||||
- `-f file` True if the provided string is a file
|
- `-f file` True if the provided string is a file
|
||||||
- `g file` True if the group id is set on a file
|
- `-g file` True if the group id is set on a file
|
||||||
- `-r file` True if the file is readable
|
- `-r file` True if the file is readable
|
||||||
- `-s file` True if the file has a non-zero size
|
- `-s file` True if the file has a non-zero size
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user