Page 1 of 1

execute through SSH

Posted: Friday 15 October 2021 13:52
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
}

Re: execute through SSH

Posted: Friday 15 October 2021 14:08
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).

Re: execute through SSH

Posted: Friday 15 October 2021 14:28
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