Shell Script in Automation

I have a shell script that works when run from the command line but I can’t get it to work in an automation.

alias: ProxmoxSSL
description: ""
trigger:
  - platform: time
    at: "02:00:00"
condition: []
action:
  - service: shell_command.proxmox
    data: {}
mode: single

configuration.yaml:

shell_command:
  proxmox: '/ssl/proxmox.sh'

Any ideas?

Your ssh terminal output above, how did you ssh to get that? It appears you are in the OS filesystem and you need to define the ssh private key in the home assistant docker file system. The warning you posted seems to support that you don’t have the keys in the docker file system.

Have you followed this guide SSH'ing from a command line sensor or shell command

I used the Home Assistant Terminal.

I just switched to using Proxmox and HAOS after a couple of years of using Debian Supervised. I can’t see where Docker is even being used now

HAOS installs Home Assistant and any Add-ons in docker containers. That makes it convenient to upgrade by simply pulling the new docker container from Github.

By “Home Assistant Terminal” I assume you mean the Home Assistant VM in Proxmox. That is not the right location. Follow the guide I posted above; it has all the information needed to correctly setup the correct shell and command line entities.

BTW, if you want to see it, just open your Proxmox host, select your HAOS VM, and then select >_ Console. You get:
image

From there type login, then enter docker ps

There are your docker containers.

This is what I didn’t know:

After storing the key elsewhere, it works now. Thanks for your help!

1 Like

Hello everybody,

I am struggling with a similar problem. I am trying to run a .sh script witch is saved on my home-assistant machine.
(The home-assistant machine is a respberry pi 4 and home-assistant was installed by using the raspberry imager).

My shell-code is “copy.sh”

#!/bin/bash

MY_BASE_FOLDER="/share/PaperlessScanFreigaben/*"
MY_TARGET_FOLDER="/share/paperless/consume"
mv $MY_BASE_FOLDER $MY_TARGET_FOLDER

To run the script automaticly I added this code to “configuration.yaml”

shell_command:
  run_copy: /bin/bash /config/scripts/copy.sh

And this code was added to “automation.yaml”

- id: 'run_copy'
  alias: 'run_copy' 
  trigger:
  - platform: time_pattern
    #minutes: '/5'
    seconds: '/30'
  condition: []
  action:
    - service: shell_command.run_copy
      data: {}
  mode: single

After 30 seconds I got thes error-message:

run_copy uses an unknown action
Bug ⸱ Reported by Automation
The automation ‘run_copy’ (automation.run_copy) has an unknown action: shell_command.run_copy.

This error prevents the automation from running correctly. This action may no longer be available or may have been caused by a typo.

image

Can enybody help my. It can not be so hard to run a simple .sh-file, is not it?

If I am runig the copy.sh file by by using

./config/scripts/copy.sh

the copy-porcess is runing fine.

Thank you

Does this change to configuration.yaml validate correctly in developer tools? Based on your error message the service isn’t created because this configuration isn’t valid.

Any reason you didn’t follow the configuration example in the documentation Shell Command - Home Assistant

# Example configuration.yaml entry
shell_command:
  restart_pow: touch ~/.pow/restart.txt
  call_remote: curl http://example.com/ping
  my_script: bash /config/shell/script.sh

They don’t use the full path of the bash command. I’m not saying yours is wrong, but that is the only difference I see between the example and your config.

Thank you for the quick answer

I didn´t use the format

 my_script: bash /config/shell/script.sh

because it do not work.

I have tried:

shell_command:
  run_copy: bash /config/scripts/copy.sh

shell_command:
  run_copy: bin/bash "config/scripts/copy.sh"

shell_command:
  run_copy: /bash/ "/config/scripts/copy.sh"

and many other combination you can use with / and ". Everything I have found in the internet the people have written how it could work I have tried.

What do you mean with

Does this change to configuration.yaml validate correctly in developer tools?

How can I prove I have done it? Everytime I change something in the configuration.yaml I run the test in the developer tools (1) by klicking (2) and then read all *.yaml new (3)

Thand you very much

Some integrations require a restart of Home Assistant, and it looks like shell_command is one of them. Have you completely restarted Home Assistant?

The reason I ask about checking the configuration is that the configuration creates a service (action) and since your error message indicates the service doesn’t exist then the configuration wasn’t loaded.

You can verify by checking the Actions tab of developer tools. If the “run_copy” action doesn’t exist in the list, then your configuration hasn’t been loaded.

image

This syntax:

my_script: bash /config/shell/script.sh
- id: 'run_copy'
  alias: 'run_copy' 
  trigger:
  - platform: time_pattern
    #minutes: '/5'
    seconds: '/30'
  condition: []
  action:
    - service: shell_command.run_copy
      data: {}
  mode: single

and a completely restart was the solution.

Thank you very much. :hugs: