매개변수가 있는 bash 스크립트를 사용하여 사용자 생성

매개변수가 있는 bash 스크립트를 사용하여 사용자 생성

(s)ftp 사용자를 생성하는 스크립트를 작성하려고 하는데 계속 실패하고 이유를 모르겠습니다. 명령을 에코하면 괜찮습니다. 복사하여 붙여넣어 사용자를 생성할 수 있지만 bash 스크립트에서 명령을 실행하면 사용자를 생성할 수 없습니다.

내가 얻는 유일한 오류는 useradd 명령의 도움말 섹션에서 발생합니다.

내가 뭘 잘못하고 있는지 아는 사람 있나요?

#!/bin/bash
# at the top are all the functions  at the bottem is the execution order
username() 
{
echo Enter the username.
read USERNAME
echo 
echo 
echo 

if [ -n "$USERNAME" ]; then
        :
        else
            echo "You didn't supply a username"
            username
         exit 1
fi
echo "the username you have selected is " $USERNAME
read -p "Is this the username you would like to use? Yy/Nn  " yn
case $yn in
    [Yy]* ) echo ;;
    [Nn]* ) username;;
    * ) echo "Please answer yes or no."; username;;
 esac
  }
groups()
{
groeps=($(cat /etc/group | grep ftponly))  #productie
#groeps=($(cat group | grep ftponly))  #local test
read -p "$(
         f=0
        for groepname in "${groeps[@]}" ; do
            # echo "$((++f)): $groepname"
     echo "$((++f)): ${groepname:0:8}"
    done


    echo -ne 'Please select the groep you would like to use > '   
 )" selection

selected_groep="${groeps[$((selection-1))]}"
echo "you have selected " ${selected_groep:0:8}
read -p "is this the right group? Yy/Nn  " yn
case $yn in
[Yy]* ) echo " " ;;
[Nn]* ) groups;;
* ) echo "Please answer yes or no."; groups;;
esac
}

 ticket()
{
echo "Enter the ticket number"
read TICKET
echo 
echo 
if [ -n "$TICKET" ]; then
    :
        else
    echo "you didnt supply a ticket number, to execute this you need to have a ticket number."
    ticket
fi
}
endcommand() 

{
echo  
echo 
DIR=/data/xchangeremote
final="/usr/sbin/useradd -g ${selected_groep:10:4} -c \"$USERNAME + $TICKET\" -d $DIR/./\"$USERNAME\" -s /usr/sbin/nologin \"$USERNAME\""
echo $final
echo "To check if the command is correct see example on: "

read -p "is the command correct now? Answer with: Yy/Nn " yn
    case $yn in
            [Yy]* ) echo ;;
            [Nn]* ) echo "please enter the correct username"; username; groups; ticket; endcommand;; 
            * ) echo "Please answer yes or no."; endcommand;;
     esac
PASSWORD=$(< /dev/urandom tr -dc '1234567890!@#$%qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM' | head -c12; echo "")
echo " the password for this account will be" $PASSWORD 
$final
$USERNAME:$PASSWORD | chpasswd
}
#here are the functions called
username
groups
ticket
endcommand

답변1

변화;

$final

도착하다;

eval "$final"

관련 정보