Bash script works ok from SSH Terminal, not when used as shell_command service in HASS.IO

Tried some more and used the absolute paths from root up to the files and adding an error output to a file (2> /config/command.log), no luck.

As you can see in the screenshot of the SSH Terminal, manually executing the script still works OK. Both from SSH landing location (~) and up to root (/) (e.g. not the /root directory).

When calling the service (using the exact same shell_command) from within HASSIO, the command.log error output file shows:

/bin/bash: /root/config/dropbox_uploader.sh: No such file or directory

BTW, both script and config files are also in the /config directory (the screenshot shows them in the ~ directory. Before someone smart mentions the path is wrong…
:wink:

It also should be run using /bin/bash, see the shebang in the script :
#!/usr/bin/env bash

Well no, because for some reason you’re using ~/config/ rather than /config/

Was not working without the ‘~’ in front of the path, I tried that as well using /config/dropbox_uploader.sh.

Strange though that the exact same command works perfectly when run in the shell itself?
Tested it with /root/config/dropbox_uploader.sh --> nope…

Current in my configuration.yaml:

shell_command:
  dropbox_uploader: /bin/bash /root/config/dropbox_uploader.sh -f /root/config/.dropbox_uploader -s upload /backup/*.tar "/hassio/" 2> /config/command.log

The output when running the script with that command in the shell:

https://hastebin.com/jiwarameze.shell

Calling the shell_command in HASSIO:

2018-08-20 21:32:38 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash /root/config/dropbox_uploader.sh -f /root/config/.dropbox_uploader -s upload /backup/*.tar "/hassio/" 2> /config/command.log`, return code: 127

command.log shows:
/bin/bash: /root/config/dropbox_uploader.sh: No such file or directory

[EDIT]

And the output using /config/dropbox_uploader.sh:

https://hastebin.com/hoxozudani.shell

2018-08-20 21:55:46 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash /config/dropbox_uploader.sh -f /config/.dropbox_uploader -s upload /backup/*.tar "/hassio/" 2> /config/command.log`, return code: 1

command.log is somehow empty…

Couple things…why do you run it as root? Not sure if hass.io works differently than Rasbian or Ubuntu but…
this works for me on both environments (the last two). I have the whole Dropbox-Uploader directory in /home/homeassistant

upload_kitchen2_motion: '/home/homeassistant/Dropbox-Uploader/dropbox_uploader.sh upload /home/homeassistant/*.mp4 uploadvid/'

I don’t need to use /bin/bash

It is a HASS.IO thing, mapping and setup of directories is not like the normal home assistant. For instance, the /www directory is only reachable as /local.
We do not have a ‘home’ folder. You only can access it as root.

And because that is a mapping I am sure of exists, I have tested putting the script files in there and use the path to that directory as well, but no luck either.

Thanks for your suggestions though.

According to Portainer (to manage Docker containers), the mapping of the homeassistant container is:

Host/volume Path in container
/usr/share/hassio/homeassistant /config
/usr/share/hassio/ssl /ssl
/usr/share/hassio/share /share

Of course I tested this path now I found it…
But, you guessed it probably by now, result:

/bin/sh: /usr/share/hassio/homeassistant/dropbox_uploader.sh: not found

Maybe I need to SSH to the host to be able to run the shell_command?

hey, did you ever figure it out? i also have those errors 1 and 127 , running from ssh works though
also running hassos here , struggling with paths also, i dont know why it works from ssh, but not from a service

Hi Fabio. No, I have since then moved to another solution for backup (Google Drive) running on a different hardware/OS setup altlogether. Never had the need to run scripts since.

yeah, is strange, my other bash scrips are working this one not , my guess is that i am using an “apk add” command, it doesnt like it i think, maybe needs sudo access

thnx anwyay :slight_smile:

Theres a pretty limited set of commands you can use. It will be running in the Home Assistant container when you run a shell command. If you open a console in that container and try and run the script you will see what is causing the problem.

my yaml code is fine, if my bash script is like :

#!/bin/bash
echo abc > abc.txt

the file is created, so that means all yaml code is good! also shell command is fired

when the bash script is like below , i receive error 1 or error 127
if i do the same apk command or the same /bin/bash /config/bash.sh from PUTTY/SSH it also works
so my guess its the HA user doesnt have the right to use the APK ADD command

#!/bin/bash
apk add can-utils

return code: 1

############

#!/bin/bash
sudo apk add can-utils

return code: 127

Did you even read what I posted to you?

How can I open a console in that container?

either via docker exec or use portainer

1 Like

it indeed gives an error there, the command works though

any idea what that means?

image

Ok, i know why, i just need to point another release, seems there is a different version for Alpine edge and Alpine 3.13 and HA doesn’t allow community packages

1 Like

Same here, always 127 error, I’ve gone through a lot posts like this one, tried all paths possible, it simply doesn’t work.

In the past I’ve used HA with Python venv and worked perfectly. Now with HASS.IO my scripts and shell commands just fail without an usefull message.

Yeah, problem is that I’d you run it from a script, it actually fires in the HA container, and you don’t see the output… In the ssh addon, the command worked for me, but not in script, so I that I did, within the ssh addon, I do the docker command to enter the HA container, from there I do the command again, to see what error 127 was, so that’s how I resolved it…

In my case I was installing an APK alpine package, but the HA container was not able to find the repository for that specific APK, seems that container was another alpine version then the SSH container, so I pointed the APK file manually

Solved

1 Like

OH! totally forgot that they’re two different containers out of the habit of working always on the same machine, lol. I’ve installed sshpass in the addon and not HA container.

Thanks!

1 Like

Remember, on reboot or update the APK packages is gone, I have an automation for that

Yup, figured it might break, I’m changing the scripts to make sure the package exists. Thank you!!

1 Like