Running shell scripts under HassOS


I’ve been a long-term user of HA, running a self-manged system on generic Linux. I understand the preference to move to a managed ecosystem, and have been playing with HassOS for a planned migration. The plan is to run HassOS on a KVM box.

I’m looking at an automation that will require logging into a remote Linux server via SSH and running some commands. I was originally planning to script it with bash and then use shell_command to execute. But HassOS doesn’t have the functionality exposed to allow it.

Has anyone created automations to manage functions on a Linux box via SSH, when using HassOS?

For sensors to get values (cpu temp, for example) from the linux box, i use mqtt_publish and cron.

To run some scripts on the linux box you can use a little mqtt listen script.


# mqtt server

# listen to mqtt topic
while read -r message
    echo "$message"
    case "$message" in
            echo "starting this"
            #/path/to/ &
            echo "starting that"
            #/path/to/ &
            echo "starting something"
            #/path/to/ &
            echo "Don't know what to do!"
done < <(mosquitto_sub -h "$MQTT_SERVER" -p "$MQTT_PORT" -u "$USER" -P "$PASSWORD" -t "$TOPIC")

Now all you need is an automation or script in HA that runs the mqtt.publish service.

It’s up to you how you start the listener on your system.
I’m running it in a screen session.

1 Like

Thanks very much for the suggestion, @VDRainer. I’ll definitely have a look.