Processing of value returned from "Run Shell Script"

Posted on
Mon Jun 17, 2019 11:54 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Processing of value returned from "Run Shell Script"

This is a feature request for the Run Shell Script action settings pane to offer the option to possibly attempt to parse the command output, or minimally, remove training line ending characters from the output.
feature-request-mockup.png
feature-request-mockup.png (76.05 KiB) Viewed 2264 times

The Run Shell Script action is actually a bit misnamed. what it really does is spawn and run something from the command line. That could be a shell script, but it could also be a built-in unix command, and there are a LOT of useful commands there, or it could be some commercial program, something from github, etc., etc. In the case of things like relay boards, many sellers provide compiled code to read or write to their boards, and pretty much 100% of those will append a newline to their output. In other words, a non-technical user might use Run Shell Script to execute some arbitrary piece of compiled code which might return a boolean output. The way Run Shell Script runs today, it captures all standard output from the executed program, including the line ending characters (eg. newline). If the newline is included, Indigo will not properly parse the output as boolean.

Posted on
Mon Jun 17, 2019 6:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Processing of value returned from "Run Shell Script"

I'm not going to argue naming semantics as the feature was added explicitly for users asking for an easy way to run shell scripts (we happened to implement it in a way that would allow basically anything to be run that is executable).

If a user desires to to any post processing of the command output, there are various ways of doing it. I don't believe this feature is used by anyone but experienced users who have the ability to manipulate any output into what they want inserted into the output variable. If it's some kind of unix command, they can run it from a script, modify the output suitably, then return it to be stored.

Indigo isn't attempting to parse the output in any way, boolean or otherwise, which is exactly the point of the feature. It just captures the output.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jul 09, 2019 8:39 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Processing of value returned from "Run Shell Script"

I now have an excellent use case that demonstrates the utility of being able to drop line-ending characters from the end of "Shell Script" output.

I recently purchased a Denkovi Ethernet DI/DO board that can be controlled by SNMP. The MacOS snmpget and snmpset commands work perfectly for enabling an Indigo Virtual Device to control the board. When setting a DO on or off, there is no issue since the SNMP command determines the DO state. However, there is also a toggle option, and this is, obviously, non-deterministic. Indigo has no immediate means to know the state of the DO after it has been toggled. However, it is possible to query the DO using an snmpget command to find the current state.
Code: Select all
/usr/bin/snmpget -v1 -c private 192.168.1.10 .1.3.6.1.4.1.42505.1.2.3.1.11.n
This command can be directly entered in the Run Shell Script config and will return a 0 or a 1 which can be saved to an Indigo variable.. However,. because the output is followed by a newline, Indigo does not see the resulting variable value as a boolean and cannot use it to set the Virtual Device's state.

There its a work-around hack, pipe the command output into tr -n "\n". However, while this works, it seems Indigo does not handle pipelines well and it throws an error in the log:
Code: Select all
 Action Collection Error         Script /usr/bin/snmpget exited abnormally with a return code of: 1
It is also possible to wrap the whole command in another program or script. But, at that point the simple utility of there built-in command is lost.

A simple fix would be an option to simply chomp (ala PERL) the line-ending characters. Better support for pipelines, etc. would also resolve the issue, but seems like overkill.

Posted on
Tue Jul 09, 2019 10:01 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Processing of value returned from "Run Shell Script"

An even simpler fix would be for you to take those two commands, with the pipe, and put them in an actual shell script, and execute that script from Indigo, it'll probably work exactly the way you want.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Jul 09, 2019 10:06 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Processing of value returned from "Run Shell Script"

FlyingDiver wrote:
An even simpler fix would be for you to take those two commands, with the pipe, and put them in an actual shell script, and execute that script from Indigo, it'll probably work exactly the way you want.

If that is what I had wanted to do, I would have done that already. This request is for people who may not know how to do that. Also, it makes it much easier to provide instructions that consist of a single command line and do not require a user to create a shell script just to run a command.

Posted on
Tue Jul 09, 2019 10:09 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Processing of value returned from "Run Shell Script"

And now we're back to Jay's last post. I think this is a dead horse.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Jul 09, 2019 10:27 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Processing of value returned from "Run Shell Script"

FlyingDiver wrote:
And now we're back to Jay's last post. I think this is a dead horse.

And, as I noted in my updated request, I disagree. Today when another user asked how I implemented a Virtual Device with snmp commands it became clear that trying to explain the creation of shell scripts or installation of python script was probably too complex to be simply conveyed on this forum. I have no idea what skill level the user possesses so I wanted to make the instructions as straight forward as possible.

Many users here are not programmers and do not want to be. Anything we can do to expand their power without adding unnecessary complexity is, in my view, a good thing. I would also note that removing line ending characters is a common enough need, especially in a scripting language, that PERL has had that capability since day one, and even enhanced it in a late release.

In any case, this topic is no more than a feature request. It seems that should provide an opportunity for discussion rather than judgement.

Posted on
Tue Jul 09, 2019 10:51 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Processing of value returned from "Run Shell Script"

I'll differ from Jay on this one, since it is something that appears to be a common (or at least not uncommon) issue: line feeds/CRs from a script output that aren't wanted and cause problems when included in Indigo variables.

Image

Posted on
Wed Jul 10, 2019 2:17 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Processing of value returned from "Run Shell Script"

Hoping to further a good discussion, and avoid a pointless debate, I would add the following for context.,
    Indigo already contains two options relates to variable processing
      The option to save the result of a shell script execution to a variable.
      When using a Virtual Device, Indigo can optionally attempt to interpret a variable value as a boolean to maintain device state.
    The requested feature would not add any new functionality, but only help make the two existing options more useful.
Stated somewhat differently, if the requested feature is inappropriate because it could be accomplished by some other means. Then, by the same token, auto-interpretation of variable values as booleans is likewise inappropriate since that too can be accomplished by external processing before being saved into a variable. In fact, even the saving the command output to a variable is unecessary since the same thing can be accomplished by an external script using the RESTFul API.

So, at least to me, it seems the real question here is about priority: Is this feature of value to enough people and use cases to merit the development time. As users, it is our job to propose features and explain why they are needed and how they might work. Then, it is up to Mattt and Jay to decide whether to add the feature to the list and at what priority.

In any case, I think I have made this request clear and leave it to Matt and Jay to handle the request as they see best for their product.

Posted on
Wed Jul 10, 2019 8:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Processing of value returned from "Run Shell Script"

Ok, we have it.

No more need for discussion.

The dead horse has been flayed into a bloody pulp.

If Matt decides it's worth his time to implement, he will do so.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 10, 2019 8:23 pm
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: Processing of value returned from "Run Shell Script"

You four are all my idols- please let me present myself as a sampling of Indigo enthusiasts who are sorta comfortable with python, but in the weeds when it comes to shell scripting. Case in point- Karl serves up shell script-related code on a silver platter, and I still struggle to make it functional.

TL;DR- +1 dumbing down shell scripts, and mom and dad please don’t fight :)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests