FIのコードに記入してください! ブラウザ経由でユーザーアカウントを作成するために、php shell_execにbashスクリプトを実行させます。私は/ etc/shadowをチェックすることで特定していますが、ユーザ名は使用されていないことをスクリプトが示しています。 これでスクリプトはuseraddコマンドを実行し、ユーザ名は/ etc/shadowに表示されます。 前にuseraddを実行して、そのユーザーが存在するかどうかを確認しますか?bashスクリプトは、そのユーザーは存在しますが、ユーザーは存在しません。
PHP
$command = "sudo ./createclientcert.sh $userName $userPass";
if(shell_exec("$command echo $?") == 0){
echo 1;
}
シェルスクリプト
#!/bin/bash
newclient() {
getent passwd $1 > /dev/null 2&>1
if [ $? -eq 0 ]; then
echo $?
else
useradd $1
echo $1:$2 | chpasswd
fi
# PLEASE TAKE NOTE!! funny thing is that when code (that had nothing to do with the account creation and was to be removed) that came after fi is in place it works well.
}
newclient "$1" "$2"
'getentをpasswdの$ 1>のを/ dev/null 2>&1 '正しくない可能性があります。それは 'getent passwd $ 1>/dev/null 2>&1'だったはずです – sjsam
また' shell_exec( "$ comm echo $?") 'は' shell_exec( "$ command echo $?") ?? – sjsam
@sjsam $ commはタイプミスでした。そのために残念。私がgooglecheckをすばやく行うと2>&1になるはずですが、別の投稿からコピーして貼り付けています。 –