0

I am running a piped ssh command on my Ubuntu 20.04 PC, where I am sshing into a remote machine, listening to a specific port and processing each incoming message as shown below:

ssh ${iotlab_ssh_front_end} "nc m3-${sink_m3} 20000 | \
while read line
do 
    seq_num=\$(cut -d';' -f2 <<< \$line)   #splits the line and stores the 2nd element
done"

What I now want is to locally (not inside the ssh) run a command (for each iteration of the loop) by making use of the variable that I am saving. I don't want to exit the loop.

Something like this:

ssh ${iotlab_ssh_front_end} "nc m3-${sink_m3} 20000 | \
while read line
do 
    seq_num=\$(cut -d';' -f2 <<< \$line)
    mosquitto_pub -t 'test/topic' -m \$seq_num      #Need to run this locally on my PC
done"

Is there a simple way to achieve this. Any help would be appreciated. Thanks!

0 Answers0