如何使用 shell 脚本在不同的终端运行不同的命令?

如何使用 shell 脚本在不同的终端运行不同的命令?

我可以访问Azure 虚拟机我打算去哪里 Hyperledger Besu 节点一个启动节点和两个验证节点。为了自动化这个设置,我创建了一个 shell 脚本。

首先,我通过运行以下命令检查终端仿真器:

echo "Terminal emulator: $TERM"

输出显示xterm-256color

基于此,我尝试运行以下命令:

xterm -e "besu --network=devnet --bootnodes --genesis-file=build/uled-local.json --data-path=build/BootNode/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8552 --rpc-ws-port=8553 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem; exec bash"

但是我遇到了错误xterm: command not found.

我还尝试了以下命令:

xterm -hold -e "publicmint --bootnodes --genesis-file=build/uled-local.json --data-path=build/BootNode/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8552 --rpc-ws-port=8553 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem"

但遇到了同样的错误:xterm: command not found.

当我使用以下命令检查终端列表时:

update-alternatives --list x-terminal-emulator

我收到以下错误:

update-alternatives: error: no alternatives for x-terminal-emulator

有人可以协助解决这些错误吗?

我已经使用过tmux但没有成功:

# Run nodes in tmux sessions
run_bc_nodes() {
    local SESSION_NAME=$1
    local WINDOW_NAME=$2
    local COMMAND=$3

    echo "Running command in tmux session: $SESSION_NAME"

    # Start a new tmux session and create a window for the node
    if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
        echo "Creating new tmux session: $SESSION_NAME"
        sudo tmux new-session -d -s "$SESSION_NAME" -n "$WINDOW_NAME" "$COMMAND"
    else
        echo "Tmux session already exists: $SESSION_NAME"
        sudo tmux new-window -t "$SESSION_NAME" -n "$WINDOW_NAME" "$COMMAND"
    fi

}

echo "############ Running Boot Node ############"
run_bc_nodes "BootNodeSession" "BootNode" "besu --bootnodes --genesis-file=build/uled-local.json --data-path=build/BootNode/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8552 --rpc-ws-port=8553 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem"

echo "############ Running Validator-1 ############"
run_bc_nodes "Validator1Session" "Validator-1" "besu --bootnodes=enode://66ada5e1d7a6e63c05be9516d37990248e3db5e5a2d7e9ec13d2852266b4dcaa7c1ac876e5eaf560e2450fdcaf093622c012a30e04b44a757870fbf8526c20cd@127.0.0.1:30303 --genesis-file=build/uled-local.json --data-path=build/Validator-1/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8554 --rpc-ws-port=8555 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --metrics-port=9441 --p2p-port=30101 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem"

echo "############ Running Validator-2 ############"
run_bc_nodes "Validator2Session" "Validator-2" "besu --bootnodes=enode://66ada5e1d7a6e63c05be9516d37990248e3db5e5a2d7e9ec13d2852266b4dcaa7c1ac876e5eaf560e2450fdcaf093622c012a30e04b44a757870fbf8526c20cd@127.0.0.1:30303 --genesis-file=build/uled-local.json --data-path=build/Validator-2/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8556 --rpc-ws-port=8557 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --metrics-port=9442 --p2p-port=30102 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem"

echo "############ Running Validator-3 ############"
run_bc_nodes "Validator3Session" "Validator-3" "besu --bootnodes=enode://66ada5e1d7a6e63c05be9516d37990248e3db5e5a2d7e9ec13d2852266b4dcaa7c1ac876e5eaf560e2450fdcaf093622c012a30e04b44a757870fbf8526c20cd@127.0.0.1:30303 --genesis-file=build/uled-local.json --data-path=build/Validator-3/node --rpc-http-enabled=true --rpc-ws-enabled=true --rpc-http-port=8558 --rpc-ws-port=8559 --rpc-http-cors-origins=* --host-whitelist=* --rpc-http-api=ETH,NET,WEB3,TXPOOL,DEBUG, --rpc-ws-api=ETH,NET,WEB3 --metrics-enabled=true --metrics-host=0.0.0.0 --metrics-port=9443 --p2p-port=30103 --tx-pool-max-size=8000 --tx-pool-retention-hours=2 --revert-reason-enabled=true --logging=INFO --rpc-http-host=0.0.0.0 --rpc-ws-host=0.0.0.0 --rpc-http-authentication-enabled=true --rpc-http-authentication-jwt-public-key-file=authKeys/puk.pem"

echo "****************** Script Completed ******************"

输出:

############ Running Boot Node ############
Running command in tmux session: BootNodeSession
Creating new tmux session: BootNodeSession
############ Running Validator-1 ############
Running command in tmux session: Validator1Session
Creating new tmux session: Validator1Session
############ Running Validator-2 ############
Running command in tmux session: Validator2Session
Creating new tmux session: Validator2Session
############ Running Validator-3 ############
Running command in tmux session: Validator3Session
Creating new tmux session: Validator3Session
Script completed

但找不到任何 tmux 进程。

相关内容