PhUser
April 3, 2023, 7:10am
1
Hello,
I want to run a command remotely on another Linux machine via SSH and save the result in an entity.
I used the following command, which works wonderfully in the SSH terminal in HA:
ssh -o LogLevel=QUIET userid@hostname -t "apt-get -qq update && apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | /bin/grep ^Inst | wc -l"
I ran ssh-keygen and ssh-copy-id in the terminal so that remote clients can log in without a password.
If I pack the whole thing into configuration.yaml, the command ends with error code 255.
- platform: command_line
name: vzlooger Linux Update
command : "ssh -o LogLevel=QUIET userid@hostname -t \"apt-get -qq update && apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | /bin/grep ^Inst | wc -l\""
Where is my mistake?
PhUser
April 3, 2023, 11:09am
3
Thanks.
When I test my command from above under
docker exec -it homeassistant bash
the command executes and I get a result back.
VDRainer
(🍻)
April 3, 2023, 11:35am
4
The command is useless with PROTECTION MODE ENABLED.
Did you read the yellow text in your screenshot?
PhUser
April 3, 2023, 12:17pm
5
Of course not done.
In summary one can say:
SSH terminal protection mode off
docker exec -it homeassistant bash
ssh-keygen -t rsa
no passphrase
save in /config/.ssh/id_rsa.pub
ssh-copy-id -i /config/.ssh/id_rsa userid@hostname
ssh -o LogLevel=QUIET userid@hostname -i /config/.ssh/id_rsa -t “my command for remote host”
And then in configuration.yaml
sensor:
- platform: command_line
name: My Entity Name
command : "ssh -o LogLevel=QUIET userid@hostname -i /config/.ssh/id_rsa -t \"my command for remote host\""
1 Like