I am trying to call a shell_command from an automation.
I have setup a simple test to add the current date/time to a logfile. The script is in /root/share:
When I run the script from a terminal, the logfile is updated as expected.
I’ve defined the shell_command in my configuration.yaml file as follows:
(I’ve tried bash, bsh, suudo. all work when invoked directly. none update the logfile when called by the automation.)
Here’s the Automation setup:
As a test automation, I invoke the script at 11:15AM, here’s the trace output:
So close, yet so far. Any help appreciated Thanks!
Please check here about where it is executed at. Shell Command - Home Assistant
The answer might depend on your installation method, home assistant operating system, supervised or core?
Yes, I saw that and should have shared installation and log info in my original post.
Home Assistant Core
Version core-2021.11.5
Operating System
Version 6.6
Installation_type: Home Assistant OS
From the log:
Error running command: sudo /share/shelltest
, return code: 127
11:15:00 AM – (ERROR) Shell Command - message first occurred at December 13, 2021, 11:15:00 AM and shows up 2 times
Which led me here:
Shell Command: return code 127 - path to script?
and here:
I need to log in?
Thanks!
/share
does not seem to be a standard mount.
Try putting the script shelltest
in your configuration directory (the directory where configuration.yaml
is) and use this instead:
shell_command:
cron_setup: /config/shelltest
Also, you should probably use an absolute path for mylog
. I’d put this in shelltest
:
#!/bin/sh
date > /config/mylog
Do not forget to make shelltest
executable: chmod +x shelltest
.
/config
will not be available outside of the homeassistant
container, but it should work in a shell command.
1 Like
@ondras12345 ding! ding! ding! That’s a winner!
Moving to /config was the fix.
Thanks!!