it seems that i need a password again - wtf ?
EDIT:
Okay i fixed the password problem
it seems that i need a password again - wtf ?
EDIT:
Okay i fixed the password problem
Based on this, openhab is the user that is running OH and will be running the script. I do not know openhabian, but I would try running the script as that user and setup the RSA key for that account. Once that is working, the Exec binding should be able to execute the script. Or you should be able to go back to the original way without the script.
i tried another way, i created a new iTunes2.sh file and it looks like this now:
When i try this script i get a “Permission denied”
( i already made i executable “sudo chmod u+x iTunes2.sh” )
[ERROR] [ab.binding.exec.internal.ExecBinding] - couldn't execute commandLine '/etc/openhab2/scripts/iTunes2.sh'
java.io.IOException: Cannot run program "/etc/openhab2/scripts/iTunes2.sh": error=13, Permission denied
Check out the posts I linked. Your OH is running under the openhab account. That is the account that needs the permissions to run the script, or whatever else you want the Exec binding to execute.
you are probably right, and i understand that i need to change the user but i dont know how to do so i am a beginner in the command line and do not understand why the openhabian image is that confusing for beginners – i thought its the hasslefree version
haha
thanks for all your ideas, links and help so far! learned a lot out of it so far thanks!
sudo chown openhab: /etc/openhab2/scripts/iTunes2.sh
should fix this.
sudo : is for command as root
chown : change owner
openhab : user name
: : change group name accordingly
/etc/openhab2/scripts/iTunes2.sh : name of file to change the ownership.
a pity - its not Radio is still playing Music…
i think you didnt read the whole thread - i created two scripts, one with “openhabian” and one with “openhab” just for testing - but still no luck…
this is still working but my exec-binding is not
What’s the exact content of iTunes.sh
and iTunes2.sh
?
In question of file permissions: the simple way would be to
sudo chmod 755 /etc/openhab2/scripts/iTunes.sh
to allow editing only for user openhab, but reading and execution for all users. Later, when all things work the right way, you can change the permissions to a more safe configuration.
both looks the same:
#!/bin/bash
toggleResult=`ssh username@192.168.1.xxx 'osascript -e "tell application \"iTunes\" to playpause"'`
echo "$toggleResult"
i tried your file permissions, but still no luck
What’s the output of
sudo -u openhab /etc/openhab2/scripts/iTunes.sh
?
Aha!
So now the problem is reduced to the login via ssh
User username
is secured via password. There is no (good) way to use password for scripted ssh. Instead you should use private keys to login. The steps for this:
ssh-keygen
sudo chmod 600 /etc/openhab2/.ssh/keyfile
)toggleResult=`ssh -i /etc/openhab2/.ssh/keyfile username@192.168.1.xxx 'osascript -e "tell application \"iTunes\" to playpause"'`
This should result in a passwordless login for user openhab
at your Mac with user username
i already created the keys, but as @5iver said,
i need to do this on the “openhab” user and not on the “openhabian” user and i dont know how to do so…
i tried “su openhab” but i dont know the default password !?
i found an interesting thread:
No, you don’t need to.
The only thing to do is, to give the correct permissions and the correct file location.
There is no relation between private key and user account, in fact, you could use whatever private/public key pair you want to use:
Altough there might be a username within the key file, it isn’t part of authentication process.
okay, but what to do ? sorry for being confused with the exec-binding…
This is no problem with exec binding, only a problem with correct permissions
I have added a few lines to my former answer…
i don’t know if it can help you i did’nt read all the post but this work for me ( openhab 2.0 mac mini 10.11 ( I think ) and itunes )
Switch playpause “Play/Pause” {exec=">[ON:ssh admin@192.168.111.2 sh /Users/admin/Script/Play.sh] >[OFF:ssh admin@192.168.111.2 sh /Users/admin/Script/Pause.sh]"}
I did not give any password because i allready configure ssh presharekey
Udo’s post has the steps, and you’ve already done 1, 2, 4 and 5.
If ~openhab exists (run echo ~openhab
and see if it returns a valid folder path), then you can do the following instead, which will allow you to not specify the private key in the ssh command. If it does not exist, continue with Udo’s instructions.
Copy the private key to the openhab account’s home directory (I’m assuming you are using RSA keys)…
cp ~openhabian/.ssh/id_rsa ~openhab/.ssh/id_rsa
and change the owner to the openhab account…
chown openhab:openhab ~openhab/.ssh/id_rsa
Then test running the script as the openhab account and you should not be prompted for a password…
sudo -u openhab /etc/openhab2/scripts/iTunes.sh
The password prompt you were getting was coming from the SSH command, because the openhab account did not have the private key in ~openhab/.ssh. The password was for the xxxxx account that you using in the SSH command in the script. On the Mac, you already setup the public key for that user.
Did you change the script to use the private key?
toggleResult=`ssh -i /etc/openhab2/.ssh/keyfile username@192.168.1.xxx 'osascript -e "tell application \"iTunes\" to playpause"'`
/\/\/\/\/\/\/\/\/\/\/\/\/\/\