Shutting down Linux server from KODI
#1
Hey all,

I couldnt find an answer by searching, but my apologies if this is a repeat.

I have all my media on an external linux machine and i play them via KODI on a RaspPi.

Im looking to see if there is a way i can configure kodi to have a button (whatever) that will run a script to shutdown my linux machine so i dont need to complete a seperate telnet connection via my phone.

essentially just looking for a way to login to an internal ip and essentially run a sudo shutdown command.

Any help would be appreciate.
-Icarys
Reply
#2
Thread moved to the Pi section
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#3
(2019-04-22, 10:29)icarys Wrote: essentially just looking for a way to login to an internal ip and essentially run a sudo shutdown command.
If you already use "sudo", then you probably use Raspbian..?

It's possible IIRC to remap a key on your remote/keyboard, and have a bash script run.
You'll have to do some forum searching here.
Reply
#4
Your problem will be is how do you input the root password to execute them sudo shutdown now command.
HTPCs: 2 x Chromecast with Google TV
Audio: Pioneer VSX-819HK & S-HS 100 5.1 Speakers
Server: HP Compaq Pro 6300, 4GB RAM, 8.75TB, Bodhi Linux 5.x, NFS, MySQL
Reply
#5
Just run the Pi fully as root. Rofl
Reply
#6
You could add an entry to your favorites in '.kodi/userdata/favourites.xml' which calls a script or directly the desired ssh command. This approach still needs a proper setup of your ssh environments because you want omit the password prompt.
Code:
<favourites>
  <favourite name="My command">System.Exec(&quot;/storage/my_script.sh&quot;)</favourite>
</favourites>


Edit: Here an complete example for the above approach:
1. Generate a ssh key on the raspberry pi
Code:
ssh-keygen -P "" -f $HOME/.ssh/shutdown_test
and write in the script, noted in the favourites entry:
Code:
#!/usr/bin/bash
ssh -i $HOME/.ssh/shutdown_test your_user@your_server
Do not forget to made the script executable… Wink

2. Copy shutdown_test.pub to the server.
3. On the server, allow 'systemctl suspend' (etc) without password prompt:
Edit etc/sudoers file ('sudo visudo') by adding
Code:
user hostname =NOPASSWD: /bin/systemctl poweroff,/bin/systemctl halt,/bin/systemctl reboot,/bin/systemctl suspend
Substitute user for your username and hostname for the machine's hostname and the path to systemctl might be differ from /bin/systemctl...

4. Finally, add following line to $HOME/.ssh/authorized_keys to allow this call over ssh with the new generated key.
Code:
command="sudo systemctl suspend",no-port-forwarding,no-x11-forwarding,no-agent-forwarding {content of shutdown_test.pub}
Reply

Logout Mark Read Team Forum Stats Members Help
Shutting down Linux server from KODI0