Is there luup code for sending ssh commands to a server?

but using just 1 of those lines works right?

If so, put your commands in a script on vera, then just call the script.

right if i put

os.execute(“ssh -i ~/.ssh/id_dss -l root 192.168.15.104 shutdown -h now”)

in a scene in vera and call the scene by anything or just press RUN it totally works…

Ok so on the CLI of the vera just create a script /root/shutdown_esxi.sh
and put in it

#/bin/ash
ssh -i ~/.ssh/id_dss -l root 192.168.15.104 shutdown -h now &
ssh -i ~/.ssh/id_dss -l root 192.168.15.105 shutdown -h now &

Add execute to it with

chmod +x /root/shutdown_esxi.sh

Then in your scene put

os.execute("/root/shutdown_esxi.sh") 

I took the easy way out… and created another scene that is triggered off the same countdown timer
(Incase the power is restored… countdown timer cancels the reboot)

so I have two separate scenes getting fired off of the one event and both servers are going down…
Both send a Pushover notification that they are going down etc.

Works for me !

Thanks again everyone… no way would I have got this done without your help!

I am struggling still with getting the os.execute function to work on my mac server

I Created a public key on my Vera
I copied that into my authorized_keys on my Server
I also appended the key with “root@vera’s_ip_address”

when I try to ssh from vera to mac, i get this error:

ssh: Connection to root@192.168.1.9:22 exited: No auth methods could be used.

I attached my permissions on client and server…

any assistance would be appreciated

As suggested in the other thread, use the -i option to explicitly specify which identity file you are using:

vera# ssh -i /root/.ssh/id_rsa root@192.168v.1.9

On the server, the only file that matters is the authorized_keys file. The text at the end of a line is only used as a comment so it can be anything. You’ve effectively put the same authorized key twice, which is harmless. The other files in the server’s .ssh directory are ignored for accepting an incoming SSH connection. Your permissions on the .ssh directory appear good.

Note that logging in to root on Mac OS X is disabled by default. You likely have to edit the /etc/sshd_config file to loosen up the permissions. Perhaps you’ve already done this if you are able to connect to this account from other hosts.

sshd sends its log to /var/log/system.log on a Mac OS X system. If you increase the LogLevel in /etc/sshd_config you can get a better idea of what auth methods are being used and why the one you expect to be used isn’t being considered.

got it,

the -i option worked

Iappreciate your help. Thanks so much!

This command is Working on my Vera :
root# ssh -i /root/.ssh/id_rsa root@192.168.1.100 ‘touch /root/test’

I can also do :
root# lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)

os.execute(“ssh -i /root/.ssh/id_rsa root@192.168.1.100 ‘touch /root/test’”)

But os.execute(“ssh -i /root/.ssh/id_rsa root@192.168.1.100 ‘touch /root/test’”) don’t work in a function in my “Edit Startup Lua” code and it don’t work as well in “Test Luup code (Lua)”.

Any idea ?

try adding backslashes to escape the quotes(') through the shell:

Instead of

os.execute("ssh -i /root/.ssh/id_rsa root@192.168.1.100 'touch /root/test'")

Try:

os.execute("ssh -i /root/.ssh/id_rsa root@192.168.1.100 \'touch /root/test\'")

you may have to mess around with getting those quotes through.

I finally manage to catch the error :
Host ‘192.168.1.100’ is not in the trusted hosts file.

know_host if ok but I think Vera didn’t search in /root/.ssh but in .ssh

I solve the problem by adding -y option :
os.execute(“ssh -y -i /root/.ssh/id_rsa root@192.168.1.100 ‘touch /root/test’”)

Thanks, Laurent

Hello

I’m trying to use the SSH to stop some of my linux machines and NAS. Everything is working fine on the ubuntu machines, but I have problems with my thecus NAS

putting the command in the CLI is working well

ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh

but when I’m trying to use it in a luup code with nothing happens !

os.execute ("ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh")

[quote=“chocorem, post:51, topic:172513”]Hello

I’m trying to use the SSH to stop some of my linux machines and NAS. Everything is working fine on the ubuntu machines, but I have problems with my thecus NAS

putting the command in the CLI is working well

ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh

but when I’m trying to use it in a luup code with nothing happens !

os.execute ("ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh")[/quote]Just a guess here, as I don’t use this method anymore.
How long does it take from the CLI? The LUUP engine might be timing out waiting for the “os.execute(…)” and killing it before it can complete.

[quote=“chocorem, post:51, topic:172513”]Hello

I’m trying to use the SSH to stop some of my linux machines and NAS. Everything is working fine on the ubuntu machines, but I have problems with my thecus NAS

putting the command in the CLI is working well

ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh

but when I’m trying to use it in a luup code with nothing happens !

os.execute ("ssh -y -i ~/.ssh/nas_dropbear root@192.168.0.100 sh /raid0/data/_tools_/shutdown.sh")

Try to debug the basic command at the Vera command line, first. Get that to work and you can drop into the os.execute command in Lua.

The only issue you will have from the first part to the second is getting the escapes correct.

the basic command is working in the CLI ! what do you mean with escapes ?

It does not matter if it works via the command line. You are running it within the Lua scripting language. You may have to escape the command as there could be a character that could be clashing with the Lua syntax.

You also didn’t answer how long the command takes to run via command line.

  • Garrett

So I managed to get it work !

I had to replace the ~/.ssh by /root/.ssh … it seems that the Lua is running under / and not /root

[tt]~[/tt] (hence [tt]$HOME[/tt]) is different inside LuaUPnP compared to a root shell. This has been mentioned before in the forum.

I’m digging out this topic because still getting some trouble using ssh commands

I’m using the following command in the CLI of the vera

ssh -y -i /root/.ssh/seedbox_dropbear root@192.168.0.90 sh /var/scripts/unisync

the unisync script on the remote machines contains the following

echo "sync started" >> /var/scripts/unison.log unison -fat -ui text -batch -logfile /var/scripts/unison.log "/home/greg/mnt/medias/TV Shows" /media/nas/videos/series_new echo "sync finished" >> /var/scripts/unison.log

the unisync.log file contains everything …

sync started UNISON 2.40.102 started propagating changes at 17:03:34.22 on 18 Oct 2014 [BGN] Copying titi from /media/nas/videos/series_new to /home/greg/mnt/medias/TV Shows [END] Copying titi UNISON 2.40.102 finished propagating changes at 17:03:34.60 on 18 Oct 2014 Synchronization complete at 17:03:34 (1 item transferred, 0 skipped, 0 failed) sync finished

While running he same command into a scene

os.execute ("ssh -y -i /root/.ssh/seedbox_dropbear root@192.168.0.90 sh /var/scripts/unisync")

the result is the following

2014-10-18 16:57:59 Started = Sync Seedbox Started 2014-10-18 16:58:01 Started = Sync Seedbox Finished

The 2 echo are running well in the script, but the unison command is not starting

does anybody has a clue ? script running at only 50 % that’s a new one !!

Hello All,

I have taken a different approach to executing singular commands on remote linux boxes. I was going to do the whole keygen process that has been described in this thread, but decided I didn’t want to fiddle too much with the vera device.

I have a couple of scripts that I run on the remote linux box that monitor for a ping request from the vera device and then act upon it.

In my case, I have it shut down a digital picture frame I built from a Raspberry Pi.

The only real downside is that you can basically only have one command.

If anybody is interested in more of the specifics, I am happy to share.

-Brett

Thanks to this thread and specifically to this post [url=http://forum.micasaverde.com/index.php/topic,11663.msg120409.html#msg120409]http://forum.micasaverde.com/index.php/topic,11663.msg120409.html#msg120409[/url], I was able to successfully configure my Edge so that it could access my Zoneminder server in order to have some control over its cameras. Vera now determines when my cameras should run by remotely executing on my ZM server a couple little bash scripts I threw together. For a Vera newbie like me this thread saved me a lot of time.

Thanks again!