DashMachine icon indicating copy to clipboard operation
DashMachine copied to clipboard

Is it possible to launch shell script by clicking a card ?

Open wake0up0ne0 opened this issue 4 years ago • 1 comments

I have some useful sh scripts on my home media server (e.g. force restart kodi, poweroff monitor). Can I launch them by clicking a card?

Probably this is a bit unsecure, but my server is in trusted LAN.

I can put those scripts it DashMachine folder if needed.

P.S.: great software, thank you, author!

wake0up0ne0 avatar Sep 16 '20 00:09 wake0up0ne0

Why not just make a dummy server to accept rpc calls? Here's a quick Python example:

app.py

import flask
import subprocess

app = flask.Flask("my_server")

@app.route("/kodi/restart")
def restart_kodi():
    subprocess.run(["/bin/bash", "restart_kodi.sh"])

@app.route("/monitor/poweroff")
def restart_kodi():
    subprocess.run(["/bin/bash", "poweroff_monitor.sh"])

app.run(port=5001)  # run on 5001 (or other) to avoid collisions

And you run it on localhost:

python app.py 

Then you define a card like this:

[Restart Kodi]
prefix = http://
url = 127.0.0.1:5001
description = Run "restart_kodi.sh"
open_in = new_tab
... 

When you click it, it will send a GET request to Flask which will run the Python code. If the only thing you need is running bash scripts (on the same host!) the code above should be fine as it is.

KMouratidis avatar Jan 14 '21 13:01 KMouratidis