execute through SSH

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
boodschap
Posts: 2
Joined: Friday 15 October 2021 13:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

execute through SSH

Post by boodschap »

I have this script I want to execute through SSH. It works perfectly in terminal, but not in my script... What am I missing?

Code: Select all

return {
	on = {
		devices = { 'Radio' },
		timer = { 'every 5 minutes' },
		},
		
	execute = function(domoticz, device)
	
		if domoticz.devices('Radio').state == 'Off' then
			os.execute ("ssh [email protected] killall mplayer")
			os.execute ("ssh [email protected] mplayer -noconsolecontrols /home/pi/domoticz/testsound.mp3 -volume 100 &> /dev/null")
		end
	
		if device.state ~= 'Off' then
			if device.state == 'Radio 1' then
				os.execute ("ssh [email protected] killall mplayer")
				os.execute ("ssh [email protected] mplayer -noconsolecontrols http://icecast.vrtcdn.be/radio1-high.mp3 -volume 100 &> /dev/null")
			end
			if device.state == 'Studio Brussel' then
				os.execute ("ssh [email protected] killall mplayer")
				os.execute ("ssh [email protected] mplayer -noconsolecontrolshttp://icecast.vrtcdn.be/stubru-high.mp3 -volume 100 &> /dev/null")
			end
		end
	end
}
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: execute through SSH

Post by heggink »

Typical problem. In order to ssh, you need to have the right credentials in place. I use passwordless ssh for which you need to exchange keys. Keys are exchanged on a per user basis so it makes a difference which user domoticz runs as. If from the command line it works then I suspect the domoticz user is a different one and you would need to exchange keys for that. Mind you, if (like with me) domoticz runs as root then you will have to exchange keys for root which is obviously a bit of a security concern (root being able to do passwordless commands).
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
boodschap
Posts: 2
Joined: Friday 15 October 2021 13:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: execute through SSH

Post by boodschap »

Ok Thank you! Changed the script, works as a charm!
sudo -u pi ssh [email protected] mplayer -noconsolecontrols http://icecast.vrtcdn.be/radio1-high.mp3 -volume 100 &> /dev/null
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest