私は、ssh経由でリモートサーバーにユーザーを追加するスクリプトを持つタスクを実行しようとしています。バッチスクリプトエラー - 予期しないファイルの末尾
はここに私のコードです:ここでadduser.txtファイルが
#!/bin/bash
#========================================================================================================
# This script allows for account creation on a server |
# It also performs error handling to ensure that the user doesn't currently exist on the system. |
# Also provides feedback from the input to verify the entries are correct. |
#========================================================================================================
while true; do
echo -n "Enter username: "
read -r username
/bin/egrep -i "^${username}:" /etc/passwd
if [ $? -eq 0 ]; then
echo "User $username already exists. Please check the username and try again."
else
echo "User $username does not exist. Proceed with account creation."
break
fi
done
adduser "$username"
if [ $? -gt 0 ]; then
echo "Error encountered."
exit 1
fi
echo -n "Enter password: "
read -r -s password
echo "$username:$password" | chpasswd
echo "Password was succesfully set for $username."
if [ $? -gt 0 ]; then
echo "Error encountered. There was a problem with your entry. Please re-run the script and try again."
exit 1
fi
usermod -a -G wheel "$username"
echo "User was succesfully added to the group wheel."
if [ $? -gt 0 ]; then
echo "Error encountered."
exit 1
fi
echo "Successfully added $username to the system."
の内容は
@echo off
setlocal enabledelayedexpansion
set username=%1
set password=%2
for /F "tokens=*" %%a in (Linuxhosts.txt) do (
ssh -i svcaccount_id_rsa [email protected]%%a 'bash -s' < adduser.txt
)
、私はCMDプロンプトを通じて、コードの最初のセットを実行しようとすると、次のエラーが表示されます。
bash: line 41: syntax error: unexpected end of file
私には分かりません。 hello.txtと呼ばれる別のファイルでテストしたところ、うまく動いていたので、テキストファイルなので見えない場所に間隔の問題があるのだろうかと疑問に思っています。
ファイルの末尾に改行を置くとどうなりますか? –
残念ながら、同じ問題が引き続き発生しています。 – ladycoder2098
私はbashスクリプトの行数を数え続けますが、私は40文字しか出ません。 – Squashman