Problems getting a Shell Script to work in crontab (outside HA container due to IPv6)

My HA install is a HAOS install on an Odroid N2+. I’m quite new to HA and have never used docker or containers before. I’m trying to get a shell script to work using crontab but am encountering road blocks.

The script (which I use on other Linux machines as well) needs to work communicate with IPv6 with the outside world. I already figured out that the HAOS container does not provide IPv6 (and indeed, it uses an internal IPv4 address when checked with ifconfig). Hence, I use the SSH & Web Terminal Add-on, which drops me into a terminal of the underlying operating system (at least eth0 shows the correct IPv4 and IPv6 addresses). I deactivated the “Protection Mode”

I have the script in a folder under root and it works when run normally. But if I add it to crontab, it doesn’t work.

It turns out that none of the changes I make persist on the file system, so maybe cron does not see the changes I make.

Proof: “md test” → “test” shows up when I do “ls”. I then restart the SSH & Web Terminal Add-On, open the terminal, and “ls” shows that “test” is gone again.

I know now what went wrong: the SSH of the SSH & Web Terminal Add-On still runs in a container, and you can only change /config. Any other change does not persist.
I actually managed to get access to the Host OS and managed to get my script working (despite the bash being a bit different apparently as I had to change some of the code), but there is no crontab there.
Will need to do things differently.

I think there should be a warning though in “SSH & Web Terminal Add-On” that nothing is persistent excelt /config. I wasted a lot of time before I found out. There is nothing in the description that explains this. So you are somewhat misled into editing crontab, making new directories, only for all to be gone.

Probably the best thing to do is to get inside the homeassistant container and get your script to run inside this container, and then use HA’s shell command to run your script and an automation to run the shell command.

2 Likes