2

我正在编写一个脚本,该脚本应该启动分布式 erlang 应用程序的多个节点(尽管在同一台机器上)。这是代码的精简示例:

start_extra_node() {
    echo "starting node $1"
    port=$((14195+$1))
    mystartcommand -p $port -n node$1 --daemonize
    res=$?
    if [ $res -ne 0 ]; then 
        echo "ERROR: could not start extra VM node $1"
        exit
    fi
    return $res
}

make_run() {
    echo " "
    echo "----------------------------------------------"
    echo "making run with $3 nodes"
    start=$2
    end=$(($3-1))
    echo "$start $end"
    for i in $(seq -s " " $start $end); do
        echo "start node $i"
        start_extra_node $i
    done
}

case $# in
    0)
        usage;;
    1)
        echo "starting node that runs the function st:$1 ..."
        start_api_node $1;;
    2)
        echo "running evaluation on 1 to $2 nodes"
        for i in `seq -s " " 1 $2`; do
            echo "make_run $1 1 $i"
            make_run $1 1 $i
        done
        ;;
    esac

该脚本使用 2 个参数调用:第一个参数在这里不重要。第二个参数是最大节点数。该脚本应该在 1 到 $2 个节点上运行一个函数。

假设我以以下方式启动脚本bash myscript foo 3

根据for 循环中的存在, mystartcommand -p $port -n node$1 --deamonizein的行为会有所不同。如果我让它失败,因为 $1 评估为. 如果我注释掉算术表达式不会失败,因为 $1 计算结果为,然后按预期计算。start_extra_nodemake_runport=$((14195+$1))1 2mystart...12

这是一个示例输出mystartcommand...

>bash myscript foo 3
...[snip]
making run with 3 nodes
1 2
start node 1 2
starting node 1 2
eval_mr.sh: Zeile 17: 14195+1 2: Syntaxerror in expression.

一个mystart...被注释掉的地方:

>bash myscript foo 3
...[snip]
making run with 3 nodes
1 2
start node 1
starting node 1
start node 2
starting node 2

我不知道如何进一步调试。我会感谢任何线索。

将 deamonize编辑为 daemonize

4

1 回答 1

2

很难想象这真的来自于忽略那个mystartcommand。应该跟$IFS东西有关系。

你可以尝试更换

for i in $(seq -s " " $start $end); do

for ((i=$start; i<=$end; $i++)); do

为了有一个真正的循环。

于 2013-11-15T08:57:04.657 回答