아래 코드를 실행하고 싶지만 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