以下のコードを実行したいのですが、viではコードのエラーが赤で強調表示されます。後にエラーが発生しましたsudo ssh -t root@$ip << EOFいいですね。私はどこを間違って書きましたか?
#!/bin/bash
cassandra_home=$(python -c "import json; print \",\".join(json.load(open('${repair.json}','r'))[\"cassandra_home\"])")
iplist[@]=$(python -c "import json; print \",\".join(json.load(open('${repair.json}','r'))[\"iplist\"])")
for ip in ${iplist[@]}
do
sudo ssh -t root@$ip << EOF
for ip in ${iplist[@]}
do
echo Checking $ip for ongoing repairs
${cassandra_home}nodetool -h $ip tpstats | grep Repair#
response=$?
if [ $response -eq 0 ]; then
repair_ongoing=true
echo "Ongoing repair on $ip"
fi
done
if ! [ $repair_ongoing ]; then
## echo "Taking a snapshot."
## ${cassandra_home}bin/nodetool -h $ip snapshot
echo "Starting repair on $ip"
start=$(date +%s)
${cassandra_home}bin/nodetool -h $ip repair -pr -inc -local metadata
sleep 3
${cassandra_home}bin/nodetool -h $ip cleanup metadata
end=$(date +%s)
#echo "ks.tab,st,et,last run,status">>repair_status.csv
echo "Repair and cleanup completed for metadata in $((end - start)) seconds"
fi
exit 0
EOF
done
答え1
使用https://www.shellcheck.net/(vimプラグインがあります)お知らせします
Line 18:
EOF
^-- SC1039: Remove indentation before end token (or use <<- and indent with tabs).
続いて、他の多くの質問をリストします。
答え2
iplist[@]
値の配列を静的宣言として保存しようとしています...
以下を試してください。
#!/bin/bash
cassandra_home=(`python -c "import json; print \",\".join(json.load(open('${repair.json}','r'))[\"cassandra_home\"])"`)
iplist[@]=(`python -c "import json; print \",\".join(json.load(open('${repair.json}','r'))[\"iplist\"])`)
for ip in ${iplist[@]}
do
sudo ssh -t root@$ip "
for ip in ${iplist[@]}
do
echo Checking $ip for ongoing repairs
${cassandra_home}nodetool -h $ip tpstats | grep Repair#
response=$?
if [ $response -eq 0 ]; then
repair_ongoing=true
echo \"Ongoing repair on $ip\"
fi
done
if ! [ $repair_ongoing ]; then
## echo \"Taking a snapshot.\"
## ${cassandra_home}bin/nodetool -h $ip snapshot
echo \"Starting repair on $ip\"
start=`date +%s`
${cassandra_home}bin/nodetool -h $ip repair -pr -inc -local metadata
sleep 3
${cassandra_home}bin/nodetool -h $ip cleanup metadata
end=`date +%s`
#echo \"ks.tab,st,et,last run,status\">>repair_status.csv
echo \"Repair and cleanup completed for metadata in $end - $start seconds\"
fi
exit 0"
done