问题
碰到了一个奇怪的问题,脚本在执行推送数据任务的时候,总是会有两个节点是失败的,确认环境都是相关的,有可能是脚本有毛病,加了堆日志后发现确实有问题。 因为之前修改数组拼接的方法。
出现问题的shell
代码语言:javascript复制#!/usr/bin/bash
devNet=(
10.40.100.114
10.40.100.115
)
testNet=(
#
10.40.100.111
10.40.100.110
)
testFn() {
local nodes=("$@")
for node in "${nodes[@]}"; do
echo "[info]: restart node: $node"
done
}
# 就因为用 " " 包起来了所以就出问题了,把两行当成一行处理
allNode=("${devNet[@]} ${testNet[@]}")
testFn "${allNode[@]}"
结果:
[info]: restart node: 10.40.100.114 [info]: restart node: 10.40.100.115 10.40.100.111 [info]: restart node: 10.40.100.110
修复后
代码语言:javascript复制#!/usr/bin/bash
devNet=(
10.40.100.114
10.40.100.115
)
testNet=(
#
10.40.100.111
10.40.100.110
)
testFn() {
local nodes=("$@")
for node in "${nodes[@]}"; do
echo "[info]: restart node: $node"
done
}
# 去掉 " "
allNode=(${devNet[@]} ${testNet[@]})
testFn "${allNode[@]}"
结果:
[info]: restart node: 10.40.100.114 [info]: restart node: 10.40.100.115 [info]: restart node: 10.40.100.111 [info]: restart node: 10.40.100.110