I'm trying to do a SSH using SSHV2. and I got it working. It now outputs msg: Object in an array[1]. Now how do I use this? I guess a Function Witch I know nothing about. and looking for your visdom here:)
This is what the debug is outputting.. Now i'm after the values "running" or "shut off"
@Stian this page in the docs provides a guide to understanding the output in the Debug sidebar and how to identify the path to any element of the message object.
Also I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour.
Hi yes I ham trying to turn off a KVM VM at night I had been using a script on Linux to do it. But now with Home Assistant and NR. I would like for the Kids to be able to Turn it on off with a switch. I have made the Switch and it runs the SSH bash command fine. But I would like to get the state of the machine in NR. and I installed the addon SSHv2 and it is working. I have added the debug output. and I am after the running in that string 0: so I can feed it into a switch then if machine is on or off turn it on or off using Call service. I am sorry but I can not acces my machine at the time to get the flow out.
This is the strng output, and I only want the last part running .. (or shutdown if it's shutdown) The awk feature in the SSH message could hav efilter this, but somehow it does not wotk using SSH client in NR. Works fine on bash in linux.
Given the data you have shown us, this function will give you "running" or "shut" (not "shut off")
let data = msg.stdout[0].split(' ');
msg.payload = data[2];
return msg;
I hope that is some help.
I have no idea how that relates to what you first said you wanted, but I know nothing about Home Assistant, KVM VM, SSHv2, yaml or even what a Call service is.
@jbudd Thx but this did not give me any more output than before. @craigcurtin here is a expanded debug. I am after the State of a VM . as you can see in the debug I get a ID if vm is up and running What I want is to get the name of VM if the VM is Off start it with a button in Home Assistant . and a Shutdown /reset VM if VM is stuck and they need to reset. it.
So the best option is if I can get the Name and State into a Switch.
What command are you running to get that output ? and can you use the same command to only get the 'hydra-vm' ? and is there perhaps a direct api available ? or an json/xml/csv output option ?
@bakman2 this is the command:
ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' sjefen@192.168.198.66 "bash -l -c "virsh list --all""
It does not work with |grep 4| awk '{ print $3 }' so I made a script to run it on the host. but I realy want to be able to only add the VM name in NR and then get state from that machine.
Here is the script. if you see any thing I can use to improw it to make this work much obliged
tmp=$(virsh list --all | grep " $1 " | awk '{ print $3}')
if ([ "x$tmp" == "x" ] || [ "x$tmp" != "xrunning" ])
then
echo "down"
# Try additional commands here...
else
echo "running"
fi
I think I got it working my quotes is wrong so I now used 'bash -lc "/path/to/script.sh argument"'
and I get running or down as expected. Thank you for all the help guys and for pointing me to try it using KIS method