我想执行下面的代码,但它在 vi 中用红色突出显示代码中的错误。在sudo ssh -t root@$ip << EOF line 之后出现错误。我在哪里编写错误的脚本?
#!/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
使用https://www.shellcheck.net/(有一个 vim 插件)它会告诉你
然后继续列出许多其他问题。
您正在尝试将值数组存储在
iplist[@]
但作为静态声明...尝试如下: