ThisIsQasim / WebGPIO

A simple web UI for controlling the GPIO pins on a Raspberry Pi
GNU General Public License v3.0
72 stars 30 forks source link

Send cmd with type:script #21

Closed Heljick closed 3 years ago

Heljick commented 3 years ago

Hi me again, I am trying to run an sshpass command via WenGPIO and can't figure out how to make it work. I tried to put the cmd into a .sh file too, work when I run it in command line but not with WebGPIO.

Here is what I tried:

or

I tried with a Timer or Action on/off but no luck :/

Heljick commented 3 years ago

ok so from my understanding this Script type in your example yml is just to get the status of a ping or a service. How is it possible to use script to actually run a cmd ? Is this only possible ?

ThisIsQasim commented 3 years ago

Hi! While I haven't tried to run a command over ssh myself. I think it should be possible to do so. Try to use ssh keys instead of a password. The command in the Status field is for checking the status via the command's exit code. If it exits with 0 exit code it will show as on otherwise it will show as off. The Status command will run every time the appliance status is checked. There is an Action: feild that takes On: and Off: as subfields where you can specify commands that should be run to turn the appliance on or off. See the example for reference https://github.com/ThisIsQasim/WebGPIO/blob/master/exampleconfig.yml

Heljick commented 3 years ago

Thanks, I have no issue with SSH, I just can't found how to run my cmd with WebGPIO. I don't need an on/off action, only a run script action when a button is pressed.

Heljick commented 3 years ago

So I succeeded to make a button working for a cmd:

Status, is useless but web interface crash if not set Timeout, just change time between status check if I am guessing right Action, no need of it as i am trying to run a cmd when button ON On, is the actual cmd I want to run Off, not needed as Action

So two things:

If you have any advice please let me know ;)

Heljick commented 3 years ago

Issue solved ! I had to force the user in order to pass the cmd, don't know why but it work.

sudo runuser -l user -c 'mycmd'

ThisIsQasim commented 3 years ago

Glad to know that it worked!