0
シェルスクリプトのwhileループでsshコマンドを使用してリモートシステムを接続する方法についてのヘルプが必要です。私はシェルスクリプトからsshを使って1つのリモートシステムに接続することができました。 ...下記のよう..シェルスクリプトのループでsshの使用に関する助けが必要
エラーを取得してループ内のコードの同じ部分を実行しようとしたssh "[email protected]" ARG1=$rpmFileName 'bash -s' <<'ENDSSH'
echo ">>Checksum ..."
md5sum /root/$ARG1
ENDSSH
「構文エラー:予期しないファイルの終わり」のサンプルコードスニペットを見つけてください、私は解決できませんでした。
しかし、同じコードを別のスクリプトファイルに置き、そのファイルを別のスクリプトのwhileループで使用すると、動作しています。
誰かが解決策を教えてくれますか?
下記の通りあなたは '-n' のsshスイッチ
などを使用しようとするかもしれません...
#!/bin/sh
rpmFileName=""
file="serverIps.txt"
dir="/home/rtulluri/downloads/EVAT-1123/AxisTar";
numberOfIps=0
axisTarfileTarget='/var'
#This function checks whether given ip is valid or not
#returns 0 for valid ip, 1 for invalid ip
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
#echo "stat = $stat"
return $stat
}
#Check whether given file exists or not
if [ -s $file ]
then
echo "$file exists"
else
echo "$file doesn't exist"
echo "exiting ........"
exit
fi
IFS=,
echo "---------------"
while read sysType serverIp uid pwd
do
sysType="${sysType#"${sysType%%[![:space:]]*}"}" # remove leading whitespace characters
sysType="${sysType%"${sysType##*[![:space:]]}"}" # remove trailing whitespace characters
serverIp="${serverIp#"${serverIp%%[![:space:]]*}"}" # remove leading whitespace characters
serverIp="${serverIp%"${serverIp##*[![:space:]]}"}" # remove trailing whitespace characters
uid="${uid#"${uid%%[![:space:]]*}"}" # remove leading whitespace characters
uid="${uid%"${uid##*[![:space:]]}"}" # remove trailing whitespace characters
pwd="${pwd#"${pwd%%[![:space:]]*}"}" # remove leading whitespace characters
pwd="${pwd%"${pwd##*[![:space:]]}"}" # remove trailing whitespace characters
if [ -n "$serverIp" ]
then
valid_ip $serverIp
#Assign the return value to a variable
isValidIp=$?
else
isValidIp=1
fi
if [ $isValidIp -eq "0" ]
then
numberOfIps=$(($numberOfIps + 1))
echo "$numberOfIps) $serverIp --> is valid"
if [ "$sysType" = "ebox" ]
then
echo "$serverIp is an eBox device.."
echo "About to pass $serverIp as argument to connct.sh"
#./connct.sh $serverIp
ssh "$address" ARG1=$rpmFileName 'bash -s' <<'ENDSSH'
echo ">>Checksum ..."
ENDSSH
fi
else
echo "$serverIp --> is invalid"
fi
echo ""
done < $file
することができます私たちはあなたがそれをデバッグすることができますので、動作しなかったコードを投稿しますか? –
そして読みやすいように(4つのスペースを字下げして)コードブロックに入れてください。 –
'ENDSSH'の前にスペースを入れましたか? whileループを表示できますか? – bmk