Shell_command not found

I did the below and have rebooted. Whenever I switch the switch it says

Failed to call service switch/turn_off. Unable to find service shell_command/shutdown_john.

In my configuration.yaml I have:

shell_command: !include_dir_merge_list shell_commands

In my switch yaml file I have:

- platform: wake_on_lan
  name: "John"
  mac: "##:##:##:##:##:##"
    service: shell_command.shutdown_john

in a file in the shell_commands folder is a yaml called shell_command_wol.yaml containing:

shutdown_john: "./scripts/ -a -b <myname> -c <my_password>"

Ive tried the above with single quotes and no quotes and taking the entry in the configuration.yaml and pointing directly to the shell_command_wol.yaml but it still doesn’t find it.

Should be:

shell_command: !include_dir_merge_named shell_commands

Thanks Phil, much appreciated that got the shell command showing in my services. I triggered it and no error on screen but got a return code 127 NoneType: None in the logs. Any idea what that is about? Comes up as an Error running command. Not sure if I need to full path the path to or not. I have a scripts folder at the same level as my shell_commands folder but maybe that’s not what that error is saying.

Edit: Full path didn’t help. Tried /usr/share/hassio/homeassistant/scripts/ and no joy

hassio? Not really sure. I don’t use it so I’m not really all that familiar with the restrictions, etc. Maybe try /config/scripts/

Nope, same deal. Not sure if /config is a valid path for my instance but maybe it’s virtual. Oddly if I put in a totally bogus path I still get the same thing so at that point it’s not even running the script. I did /config/scriptss/ with two s in scripts.

Also if I run the script manually on the Linux box as the homeassistant user it reboots the PC.

For hassio I’m led to understand that /config is the path to the folder that contains configuration.yaml. So if is in a subdirectory of that named scripts, then it should be like I said, /config/scripts/ Why would you make it scriptss???

What is the exact error message?

Because I am testing. So if the “right” path is giving an error, what would the wrong path give? No one say’s it’s a path issue may be something in the shell script. So by making sure the path is wrong and the error is the same, shows it’s not my code. Or not yet since it doesn’t even look like it’s getting to it.

The exact error:

2020-01-10 16:10:05 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: /scripts/ -a -b domain/name -c mypassword, return code: 127
NoneType: None

" Value 127 is returned by your shell /bin/bash when any given command within your bash script or on bash command line is not found in any of the paths defined by PATH system environment variable."

Did you try /config/scripts/

Yep. I have been digging a bit and seeing some people that say you need to ssh in to run this or something and need some kind of certs or something. Trying to get more details.

SSH was the answer. Took some work to figure out but had to generate some certs and the like.

That said, I am finding there are certain circumstances where WOL will work and others where I need to run a script to turn something back on. Like if it’s a virtual it’s not listening so need to trigger it by script. I would like one nice interface though that is for all computers. Some would be turned on by WOL, others by scripts. i assume I would probably either need to abandon the WOL platform or split things up where the direct computers use WOL and the virtuals maybe do something where I have to ping them to see if they are on and if you flip a switch SSH into my Windows machine running VMware workstation and run a batch to turn on the selected virtual?

I am having a very similar issue - trying to execute a script to copy my backup snapshot to another server in the house.


backup_file=$(/usr/bin/find /backup -iname '*.tar' -print0 | /usr/bin/xargs -r -0 ls -1 -t | /usr/bin/head -1)

/usr/bin/scp $backup_file root@tower:/mnt/user/Backup/HomeAssistant

shell command as defined in configuration.yaml:

  copy_backup_to_tower: bash /backup/

When invoked as part of an automation, I get this in the logs:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/
Integration: Shell Command (documentation, issues)
First occurred: 9:46:17 AM (4 occurrences)
Last logged: 10:03:59 AM

Error running command: `bash /backup/`, return code: 127
NoneType: None

As you can see, I fully qualified every command - I can’t imagine what command is not found?

Of course it runs fine from the command line.

You need to install keys on the 2 machines. It’s different from the keys that are exchanged when you first ssh in. Follow this guide.

Thanks, I’ll give it a shot, but my destination backup server account doesn’t have a password. So when I say it works from the commandline, I don’t have to input a password. Do I still need keys?

SSH = Secure SHell Protocal. I believe regardless if the server has a password, the application(ssh) requires authentication. HA also runs in a container separate from ssh so the key is needed for HA to run a command in another container.