Kodi Starter script for linux: Linux script to start Kodi from Yatse (NeoAcheron)

This post was originally made on previous version of the forum by NeoArcheron


Hi there,

Love your remote app. Its definitely the best XBMC remote ever. However I recently ditched my Windows installation for a linux one and I found that the only feature lacking was a way to let Yatse launch XMBC automatically, just like in Windows with your autostart utility.

So I spent a few minutes writing a little BASH and came up with a script that can be easily started by your linux distribution’s startup manager as a daemon.
PS: Certain distro’s net to install tcpdump separately, so make sure it is installed and working before attempting to run this utility script.

I placed the following into /home/xbmc/autostarter.sh and made the file executable by all:

#!/bin/bash

UDP_PORT=12          # Change this if you need to run this on a different port, just remember to update Yatse's settings as well
RUN_XBMC_AS=xbmc     # Change this if you need to run it as another user

START_PHRASE="YatseStart-Xbmc"    # Do not touch this, unless you know what you are doing...

# The following block checks if the user running this script has the required privileges to listen on the port specified above
   WHO=`whoami` 
   if [ "$WHO" != "root" ]; then
      echo "Unprivileged users may not evesdrop on ports. Cannot start unless running as root."
      exit 1
   fi


echo "Listening on port $UDP_PORT for Yatse remote start command"

while [ true ]; do
   # Wait for a packet to come in from Yatse
   LISTEN=`tcpdump "udp port $UDP_PORT" -A -c 1 2>&1 | grep -o "$START_PHRASE"`
   # Make sure that we received the right command
   if [ "$LISTEN" = "$START_PHRASE" ]; then
      echo "Starting XBMC as $RUN_XBMC_AS"
      # Start XBMC using sudo -u to run it using the username above
      # If you need to you can replace the xbmc command below with xbmc-standalone if you are not using a window manager
      sudo --user=$RUN_XBMC_AS xbmc
   fi 
   # Sleep, to be nice, for unwanted rogue processes writing to our port
   sleep 1
done   

Hope this is as helpful to someone else as it is to me.

Kindest regards,
NeoAcheron

1 Like

I came here looking for the visa versa send a command from linux to open my shield tiv
From what was written here I figured I should just send a UDP packet with the magic string

echo “YatseStart-Xbmc” | nc -w 2 -C -u -N 192.168.1.5 5600

The above did the trick for me

1 Like

That’s great! I was just looking for such a script :slight_smile:

I had to perform the following 2 modifications in order to get it to work on Kodi18
I changed count (-c option in tcpdump) to 2, as the phrase is actually received on the 2nd packet
LISTEN=tcpdump "udp port $UDP_PORT" -A -c 2 2>&1 | grep -o "$START_PHRASE"

And I had to change the start command to sudo -u, and “xbmc” to “kodi”
sudo -u $RUN_XBMC_AS kodi

Thank you very much NeoAcheron!

Hello, one question. Is it possible to use that script on a Raspberry Pi 3, running as a Magic Mirror with Raspbian Buster and Kodi 18.4? I tried with standard settings and also with the settings of DrGonzo but without success. Any ideas or recommendations?

This topic may be old, but it is a bit of gold dust.

Home Assistant user here. Used a variation of this to start KODI from HA

shell_command:
start_kodi: “echo -n ‘YatseStart-Xbmc’ | nc -u -w1 192.168.1.5 5600”

Maybe this will pickup on a keyword search. And a Home Assistant user will know what to do with the above YAML. (If not ask and I will reply)

Meanwhile - Tolriq you a hero for a brilliant app that keeps giving. I gotta go donate again cos Android Auto works so well with my new Kenwood head unit. Happy Yatse user for long time. And bonus XMBCstarter solving my other puzzles :smiling_face_with_three_hearts: :partying_face:

Hi, the truth is that I’ve been thinking about bash so much and I haven’t managed to start kodi remotely. Could someone please help me?
I’m on kodi 21 (kde neon) my user is ruben.
Thank you