As part of a distributed control system I want to mirror in HA the presence or absence of a file on a remote, insecure, server.
My chosen approach is to regularly check the remote system for the file in question and update the local system appropriately. At the moment I have:
- A shell script ‘/config/script.sh’ which manages the mirror:
#!/bin/bash
ssh -q user@remote [[ -f remote_file ]] && touch /config/local_file || rm -f /config/local_file
If I execute /config/script.sh from the HA terminal then it accurately creates / deletes /config/local_file dependent upon the presence or absence of remote_file.
- A shell command alias (myscript) for /config/script.sh set up in configuration.yaml:
shell_command:
myscript: /config/script.sh
- An automation to execute /config/script.sh once a minute.
- id: 'schedule_1m'
alias: 'Schedule: every minute'
description: ''
trigger:
- platform: time_pattern
minutes: '/1'
condition: []
action:
- service: shell_command.myscript
data: {}
mode: single
The automation executes every minute, but the ssh test on the remote server always fails. There are no errors: with the flag file present on the remote server I can execute script.sh and see the local flag file appear on my system, but it will shortly be removed as the automation executes script.sh.
My suspicion is that the environment in which ssh is being executed within the automation is limiting something - perhaps the ssh key for the remote server is not accessible from within the shell_command context?
I wonder if anyone has any thoughts?