Running custom command in ubuntu cli from automation

Hi.
Running: Ubuntu Server 16, and newest hass.io.

I want to be able to run a script (powershell in my case) from the command line cli and specify the scriptfile in an automation.
I foundthis solution, but ut don’t work (also 3 years old).

This is my configuration.yaml config:

shell_command:
  run_sudo: sudo "{{cmd}}"

this is my automations.yaml config:

- id: '1562762467593'
  alias: PS Test
  trigger:
  - entity_id: switch.zwave_1
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
    - service: shell_command.run_sudo
      data:
        cmd: 'pwsh -file /usr/share/hassio/homeassistant/powershell_script/output_date.ps1'

And this is my powershell_script\output_date.ps1 script file:

Get-Date | Out-File "/usr/share/hassio/homeassistant/powershell_script/test.txt"

It works if I run in in cli, but not if the automation is triggering it.

What is wrong, or is it any better way to do this?

So hassio runs in docker and if you don’t mount the location of your script to your docker container then hassio doesn’t have access to it . That’s the point of docker, it’s a container and it runs separately from your system.

You can setup SSH and use that to log into the host machine then run the script (this is quite slow and sometimes doesn’t work well especially on getting the current state).

Thanks for your answer.
The scripts is located under /usr/share/hassio/homeassistant/, but maybe the issue is that pwsh is?

In that case, is there a way to make it work by mounting that?
Keep in mind, I am not very experienced with Linux or docker.

bumping this

sorry, i don’t check this often. I don’t really know docker all that well so I’d have to defer to someone else. But basically docker is self contained so even if your script is within the home assistant config folder it won’t have powershell as it isn’t part of the container and thus you can’t run a powershell script unless you access the host machine and run it there (hence my comment above about ssh to host machine and execute as part of the ssh connection). Any reason it needs to be a powershell script vs a linux bash script?

I haven’t written a powershell script in 4-5 years so I’m not exactly sure what you’re trying to do. Perhaps rather than trying to get powershell to work, you could explain what your end goal is and someone could help you write the bash file.

@flemmingss how did you get pwsh installed?

I am running Hass OS (I downloaded the official full VM with HASS already installed) and it doesn’t seem to have apt or apt-get or yum