サーバーにログインし、サーバーで実行されているプロセスを開始および停止するいくつかのコマンドを実行するためのシェルスクリプトを作成したため、次のコードを試しましたが、エラーが表示されます。スクリプトについて助けてください。
for i in 'cat /tmp/hb` //server name would be saved in /tmp/hb
ssh $i
j=hostname
If $i -ne $j
then
echo "server not logged in"
else echo "Server logged in"
if
$i == $j
sudo /opt/OV/bin/opcagt -status |grep -i ”message agent are not buffering"
elif
sudo /opt/OV/bin/opcagt -stop
sudo /opt/OV/bin/opcagt -start
sudo /opt/OV/bin/opcagt -stop
sudo /opt/OV/bin/opcagt -status |grep -i ”message agent are not buffering
elif
sudo /opt/OV/bin/opcagt -kill
sudo /opt/OV/bin/opcagt -start
sudo /opt/OV/bin/opcagt -status |grep -i ”message agent are not buffering
fi
上記のスクリプトではエラーが発生します。
./heart: syntax error at line 2: `ssh' unexpected
ベストアンサー1
最初の問題は、aによって繰り返されるブロックが周囲にandブロックをfor
持つ必要があることです。do
done
for f in `cat file`
do
...
done
2番目の問題は、残りのループ本文(ステートメント)がターゲットホストのセッション内で実行されif
ないことです。どういうわけかステートメントをターゲットホストにプッシュし、そこからスクリプトを実行する必要があります。ssh
if