作者 主題: bash script- create a user and a group  (閱讀 1617 次)

0 會員 與 1 訪客 正在閱讀本文。

rita299

  • 可愛的小學生
  • *
  • 文章數: 1
    • 檢視個人資料
bash script- create a user and a group
« 於: 2020-11-28 10:33 »
想請教如何寫一個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
« 上次編輯: 2020-11-28 12:06 由 rita299 »