Page 1 of 1
Run Terminal Commands on Request
Posted: Sunday 10 January 2016 13:16
by simon_rb
Hi,
I have tried to search for this however I don't quite know how to word it. I'm installing
https://www.npmjs.com/package/ps4-waker to wake my PS4. Just trying to work out how Domoticz could execute the wake and suspend commands.. Hope to have a dummy switch which will call a script to execute but I have no idea how to do that. Domoticz and ps4-wakes are running on the same raspberry pi.
Thank you
Re: Run Terminal Commands on Request
Posted: Sunday 10 January 2016 14:38
by oliviers
Hi,
I believe this should do it : (assuming you're on Linux):
1. Write a simple bash script like this one:
Code: Select all
#!/bin/bash
# Start my PS4
ps4-waker [options] > /dev/null &
The & at the end ensures that the script won't "hang" if the command takes time to execute. Domoticz doesn't like long-running scripts
2. Save it as start_ps4.sh in /home/pi/domoticz/scripts
3. Give it execution rights (chmod)
4. In your dummy script configuration, in "Action on", point to your script:
Code: Select all
script:///home/pi/domoticz/scripts/start_ps4.sh
That's it ...
Oliviers
Re: Run Terminal Commands on Request
Posted: Sunday 10 January 2016 17:26
by simon_rb
Oliviers,
Worked great! Thanks

Re: Run Terminal Commands on Request
Posted: Thursday 30 May 2019 14:51
by McJohn
Can anyone tell me why this script is working perfectly in the terminal but not with Domoticz?
Code: Select all
#!/bin/sh
xscreensaver-command -deactivate > /dev/null &
Path to the script from Domoticz:
///home/pi/domoticz/scripts/xscreensaverdeactivate.sh
Script is running within Domoticz but nothing happened:
2019-05-30 14:50:03.468 Status: Executing script: ///home/pi/domoticz/scripts/xscreensaverdeactivate.sh
Thanks for the help!
PS: the script has all rights for everyone to read and write.
Re: Run Terminal Commands on Request
Posted: Thursday 30 May 2019 21:52
by waaren
McJohn wrote: Thursday 30 May 2019 14:51
Can anyone tell me why this script is working perfectly in the terminal but not with Domoticz?
Code: Select all
#!/bin/sh
xscreensaver-command -deactivate > /dev/null &
Path to the script from Domoticz:
///home/pi/domoticz/scripts/xscreensaverdeactivate.sh
Script is running within Domoticz but nothing happened:
2019-05-30 14:50:03.468 Status: Executing script: ///home/pi/domoticz/scripts/xscreensaverdeactivate.sh
Thanks for the help!
PS: the script has all rights for everyone to read and write.
Can you try to execute the script as the same user as you use for domoticz ? The script may be accessed by every user but it could well be that the commands inside are not.
Re: Run Terminal Commands on Request
Posted: Thursday 30 May 2019 22:55
by McJohn
Thanks for your feedback!
We use different other .sh scripts and they are working well with Domoticz.
This is the first one with a terminal command.
Is it possible to edit the script that it could be fired by everyone?
What is the default user for Domoticz?
Thanks for your help.
Re: Run Terminal Commands on Request
Posted: Thursday 30 May 2019 23:10
by waaren
McJohn wrote: Thursday 30 May 2019 22:55
Is it possible to edit the script that it could be fired by everyone?
What is the default user for Domoticz?
You stated that the script can be access for read / write by everyone. Is that also true for executing the script ?
identify the domoticz user by the CLI command
If you need the commands inside the script to be processed by the domoticz user the you could try to put a
sudo <space>
in front of the failing commands in the script.
Re: Run Terminal Commands on Request
Posted: Friday 31 May 2019 10:15
by McJohn
Thanks for your tips & tricks.
I placed a sudo command in the first line into the script.
Nothing changed, it won’t work.
When I run the script (with the sudo command in it) remote from an ssh session, I got an error:
No protocol specified
Without the sudo command in the script it works perfectly with the SSH session; remote the Raspberry Screen wakes up!
The script has all rights for everyone, also for executing the script.
See screendump.
ps -ef | grep domoticz
gives:
root 657 1 8 mei30 ? 01:30:39 /home/pi/domoticz/domoticz -daemon -www 8080 -sslwww 443
pi 8984 8790 0 10:03 pts/1 00:00:00 grep domoticz
So, with a remote session, with user John, the script works perfectly:
pi@John:~$ /home/pi/domoticz/scripts/xscreensaverdeactivate.sh
Why won’t it work with Domoticz?
Re: Run Terminal Commands on Request
Posted: Friday 31 May 2019 11:42
by waaren
So domoticz runs as root and root cannot succesfully executes the command.
So try something with runuser or the likes.
Google for the exact syntax.
I am not at home so limited access to Linux system.
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
Re: Run Terminal Commands on Request
Posted: Friday 31 May 2019 12:33
by McJohn
Thanks for your time.
I’m not an unix expert. I tried something like this:
I added into the script:
runuser
gives this result (from an ssh session command to the script);
runuser: ongeldige optie -- 'd'
When I tried into the script:
runuser -u
gives this:
runuser: ongeldige optie -- 'd'
su -c
gives this:
su: dient uitgevoerd te worden vanaf een terminal
Sorry.
Re: Run Terminal Commands on Request
Posted: Saturday 01 June 2019 11:32
by waaren
McJohn wrote: Friday 31 May 2019 12:33
When I tried into the script ...
runuser: ongeldige optie -- 'd'
Can you try with this
Code: Select all
#!/bin/sh
runuser -l John -c 'xscreensaver-command -deactivate' 2>&1 > /tmp/xscreensaver-command.out &
Re: Run Terminal Commands on Request
Posted: Saturday 01 June 2019 14:11
by McJohn
Thanks for the help, I appreciate that.
I did what you asked and edit the script.
Then I tested with an ssh session:
With user John in the script:
It says:
pi@John:~$ runuser: user John does not exist
With user pi in the script:
runuser: may not be used by non-root users
With user root in the script:
runuser: may not be used by non-root users
It’s driving me crazy….
Re: Run Terminal Commands on Request
Posted: Saturday 01 June 2019 14:44
by McJohn
YESSS!!! It’s working!
I think with the remote ssh terminal session the rights won't accept an action locally from user "pi" (the owner of the script, see above screen dump).
BUT; with owner “pi” in the script it’s working perfectly directly from Domoticz at the Raspberry.
Now, with a specific Domoticz action we can wake up the Raspberry screen.
Thank you very much for the giant hint!
