dimanche 19 juillet 2020

How to look for user from input and create user if don't exist

I'm trying to create a shell script that ask for user input. If the user exist it lets you know; if the user doesn't exist it creates the user and password and adds them to a group. However, I am stuck and am hoping someone can assist. It seems to stop after it reads the response and doesn't execute the if/then

Here is what I have so far:

#!/bin/bash

echo "Which user would you like to use docker? "
read -r user

getent passwd "$user" > /dev/null 2&>1 && echo yes || echo no
read -r response

if [ "$response" == "yes" ];then
        echo " User already exist"
if [ "$response" == "no" ];then
        useradd -m $user
        passwd $user
        usermod -aG docker $user
fi
fi

Aucun commentaire:

Enregistrer un commentaire