#!/bin/bash
# read comm
newNode_passed=0
if [ $# -gt 0 ]; then
    newNode_passed=$1
fi

comm="$(tail -n 100 logs_check | grep MOSH | tail -n 1)"
echo \"$comm\" found from remote

if [ -z $comm ]; then
    echo need pass COMM to make
    exit 1
else
    lastServer=$(tail -n 1 serverNodes)
    newNode=$((lastServer + 0))

    if [ ${newNode_passed} -gt $newNode ]; then
        newNode=${newNode_passed}
    fi

    pcomm="$(echo $comm | sed "s/600[0-9]\{1,\}.*\r/$newNode/")"
    echo \"$pcomm\" will be used
    hn=$(echo $comm | cut -d" " -f 5)
    #tmux select-pane -t rvsConnector -m
    #tmux select-window -t rvsConnector:$
    tmux new-window -d -t rvsConnector -n "m.$hn.$(git show --no-patch --oneline)" "bash -c \"$pcomm\""
    #tmux last-window -t rvsConnector
fi
