技術討論區 > Linux 討論版

bash script- create a user and a group

(1/1)

rita299:
想請教如何寫一個BASH SCRIPT create a user and a group(if the group is not exist)

#!bin/bash
read -p "Enter USERNAME: " userNAME
read -p "Enter USERGROUP name: " userRGROUP

grep $USERGROUP /etc/group 2>&1> /dev/null

while [ $? -eq 0 ]
        read -p "Enter USERNAME: " userNAME
        read -p "Enter USERGROUP name: " userRGROUP
grep $USERGROUP /etc/group 2>&1> /dev/null
        printf "Group Name you entered $USERGROUP is not valid\n"
        printf "Creating Abort!"\n"
        exit 1
do
        useradd -g $USERGROUP -d /home/$USERNAME -s /bin/bash -m $USERNAME
        passwd $USERNAME
done

id $USERNAME

printf "Done!\n"

exit 0

導覽

[0] 文章列表

前往完整版本