Read output from sh script

I have a .sh script that connect to a network box and received some info the I query. I want to use the “reply” from the network box to set a state of a switch.

Anybody knows if that is possible? If yes, how?




At least 3 ways I know of

  • use mqtt publish to send ‘reply’ as message to a mqtt sensor,
  • use curl POST to api/state/sensor.[your sensor] REST api
  • echo ‘reply’ to a file and use file sensor
1 Like


Thanks for the reply. I’m a linux noob, so if you can help with some examples :slightly_smiling_face:

I have two switched. “Light 1” and “Light 2”

I have a sh file with this content:

{ echo “>>Login xxxxx<<”;sleep 1;echo “>>Get 40864<<”;sleep 1;echo “>>Get 40849<<”;sleep 1;echo “>>Logout<<”; } | nc 88888

The “reply” from the sh script is this when I parse it to a txt file:

Logout Ok<<
Login Ok<<
Get 100<<
Get 0<<

“Get 100” means the switch in line 3 (Light 1) is “On” and “Get 0” means switch in line 4 (Light 2) is “Off”

I would like to update the state of switch “light 1” and “light 2” bases on the outcome from the script. So “Light 1” will be set to “On” and “Light 2” will be set to off.

Is this possible and can anyone prove an example?