Run Terminal Commands on Request
Moderators: leecollings, remb0
-
simon_rb
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Run Terminal Commands on Request
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
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
-
oliviers
- Posts: 74
- Joined: Wednesday 16 September 2015 22:10
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Paris area, France
- Contact:
Re: Run Terminal Commands on Request
Hi,
I believe this should do it : (assuming you're on Linux):
1. Write a simple bash script like this one:
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:
That's it ...
Oliviers
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 &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.shOliviers
Paris area
Raspberry Pi 4 - RFXComm 433 - IrTrans - Zwave
Raspberry Pi 4 - RFXComm 433 - IrTrans - Zwave
-
simon_rb
- Posts: 612
- Joined: Wednesday 07 August 2013 19:09
- Target OS: -
- Domoticz version:
- Location: UK
- Contact:
Re: Run Terminal Commands on Request
Oliviers,
Worked great! Thanks
Worked great! Thanks
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
Can anyone tell me why this script is working perfectly in the terminal but not with Domoticz?
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.
Code: Select all
#!/bin/sh
xscreensaver-command -deactivate > /dev/null &
///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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Run Terminal Commands on Request
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.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?
Path to the script from Domoticz:Code: Select all
#!/bin/sh xscreensaver-command -deactivate > /dev/null &
///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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
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.
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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Run Terminal Commands on Request
You stated that the script can be access for read / write by everyone. Is that also true for executing the script ?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?
identify the domoticz user by the CLI command
Code: Select all
ps -ef | grep domoticz sudo <space>
in front of the failing commands in the script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
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?
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?
- Attachments
-
- Screen Shot 2019-05-31 at 10.12.26.png (166.14 KiB) Viewed 2415 times
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Run Terminal Commands on Request
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
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
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.
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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Run Terminal Commands on Request
Can you try with thisMcJohn wrote: Friday 31 May 2019 12:33 When I tried into the script ...
runuser: ongeldige optie -- 'd'
Code: Select all
#!/bin/sh
runuser -l John -c 'xscreensaver-command -deactivate' 2>&1 > /tmp/xscreensaver-command.out &Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
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….
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….
-
McJohn
- Posts: 91
- Joined: Wednesday 10 October 2018 17:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: Run Terminal Commands on Request
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!
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!
Who is online
Users browsing this forum: No registered users and 1 guest