在 bash 脚本中同时运行 ssh 命令和另一个命令

在 bash 脚本中同时运行 ssh 命令和另一个命令

我有以下脚本

#!/bin/bash
for (( c=0; c<=9; c++ ))
do  
    ssh -t 192.168.30.11 "tshark -i eth1 -f 'src host 192.168.31.10 and tcp' -w shared_folder/results/bbb_var_4_exp_pcaps/capture-output-$c.pcap -a duration:205" &
    python ~/shared_folder/tapas/play.py -u http://192.168.31.10/video-content/mm_videos/bbb_var_4/bbb_var_4.m3u8 -m fake -l my-exp-logs/bbb_var_4_exp_logs 
    sleep 210
done

ssh我正在尝试在后台运行该命令,第二个命令python不需要第一个命令来完成。但是当我将 & 添加到 ssh 命令行末尾时,它就会挂起。

有任何想法吗?

答案1

我认为该参数与将命令发送到后台不-t兼容。ssh

选项1

省略-t

ssh remote-machine 'command' &

选项2

发送偏僻的进程到后台。你可能需要将远程进程与 stdin、stdout、stderr 分离允许ssh立即返回:

ssh -t remote-machine 'command < /dev/null &> /dev/null &'

相关内容