0

Ubuntu 20.04 LTS Shell

1.

mosquitto_sub -h 192.168.1.3 -t "application/2/device/df9cde4119c814ef/rx" -v
application/2/device/df9cde4119c814ef/rx {"applicationID":"2","applicationName":"E78","deviceName":"E78-DTU","devEUI":"35zeQRnIFO8=","rxInfo":[],"txInfo":{"frequenation":"LORA","loRaModulationInfo":{"bandwidth":125,"spreadingFactor":9,"codeRate":"4/5","polarizationInversion":false}},"adr":false,"dr":3,"fCnt":15,"fPort":65,"dectJSON":"","tags":{}}
  1. (mosquitto_sub -h 192.168.1.3 -t "application/2/device/df9cde4119c814ef/rx" -v)|grep dev
    application/2/device/df9cde4119c814ef/rx {"applicationID":"2","applicationName":"E78","deviceName":"E78-DTU","devEUI":"35zeQRnIFO8=","rxInfo":[],"txInfo":{"frequenation":"LORA","loRaModulationInfo":{"bandwidth":125,"spreadingFactor":9,"codeRate":"4/5","polarizationInversion":false}},"adr":false,"dr":3,"fCnt":47,"fPort":65,"dectJSON":"","tags":{}}
    
  2. (mosquitto_sub -h 192.168.1.3 -t "application/2/device/df9cde4119c814ef/rx" -v)|cat
    application/2/device/df9cde4119c814ef/rx {"applicationID":"2","applicationName":"E78","deviceName":"E78-DTU","devEUI":"35zeQRnIFO8=","rxInfo":[],"txInfo":{"frequenation":"LORA","loRaModulationInfo":{"bandwidth":125,"spreadingFactor":9,"codeRate":"4/5","polarizationInversion":false}},"adr":false,"dr":3,"fCnt":36,"fPort":65,"dectJSON":"","tags":{}}
    
  3. (mosquitto_sub -h 192.168.1.3 -t "application/2/device/df9cde4119c814ef/rx" -v)|awk '{print $1; fflush()}'
    
  4. (mosquitto_sub -h 192.168.1.3 -t "application/2/device/df9cde4119c814ef/rx" -v)|xargs
    

In 1,2,3,the shell command can output normally. But in 4,5, the shell command can output nothing.Why?

how to fix 4,5 to output normally?

2
  • This is off topic, it would probably be best asked on SuperUser. (p.s. the reason will be because mosquitto_sub doesn't return, it hold stdout open continues to write new messages to it forever. awk will wait to read the whole output in before outputting.
    – hardillb
    Commented Jul 9, 2023 at 7:53
  • There are dedicated cli tool to run a command on a MQTT message
    – hardillb
    Commented Jul 9, 2023 at 11:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.