Run a script via miniDLNA

Anonymous
2012-02-20
2014-08-13

  • Anonymous
    2012-02-20

    Can anyone help me out with this? I would like to have a way to turn my computer off via my TV. I was wondering if there was anyway this could be done via miniDLNA.

    I was thinking something along the lines of a file that miniDLNA would recognise and when selected via the TV it would run a simple script on my Ubuntu pc that shuts the pc down.

    Any ideas suggestions?

    p.s. this is just an idea I personally want to complete, I don't think it should be part of the official minDLNA.

     

  • Anonymous
    2012-03-01

    At first I was thinking that's a great idea but a security hole as there is no authentication.  But its for a local network and a non-standard feature.

    However really and truly you could do this with a separate application.  Create an application that watches for when a file is accessed and then perform a command.  Obviously the process would have to be given sufficient rights to shutdown a computer but that's not really hard.

    I'll give it a try and post back my results.

     
  • Craig Chambers
    Craig Chambers
    2012-03-01

    Following from the above suggestion…
    The following command evaluates if a file is open, and executes the appropriate command if it is…

    if  ; then echo "nano is open" ; else echo "no nano"; fi

    Basically, if I have nano open, then run the above in a shell, it prints "nano" to the shell.

    You could expand on this and have a minutely cron job run by root (or a similarly shutdown privileged user) that checks for an open specific media file (rather than nano), and if it finds it executes the shutdown command. e.g. something like…

    #!/bin/bash
    if  ; then shutdown -h now ; fi

    Put that into a command (say /home/myaccount/bin/my_shutdown_script.sh)
    Make it executable (chmod +x /home/myaccount/bin/my_shutdown_script.sh)
    Test it (run it manually while your TV is playing the file /home/myaccount/bin/my_shutdown_script.sh)
    Put the script into crontab (sudo crontab -e) entry as below…

    * * * * * /home/myaccount/bin/my_shutdown_script.sh

    I have no idea if a media file playing from minidlna shows as 'open' but give it a try.

     

  • Anonymous
    2012-03-01

    Thanks for the advice guys.
    This is my script so far:

    #!/bin/sh
    inotifywait -e open /media/Documents/Video/Shutdown.avi | while read FILE
    do
    shutdown -h now
    done

    If I run this from the terminal and then access Shutdown.avi from the TV is does shutdown the PC :)

    My issue now is how to get this script to run from start up in some sort of background thread.
    Any advice?

     
  • Craig Chambers
    Craig Chambers
    2012-03-05

    Add it to a System V init script, or upstart script (depending on your platform and/or preference).  Minidlna has a System V start-up script you can look at as an example.

     

  • Anonymous
    2012-03-05

    I did that originally but due the nature of my script the system just hangs until the script is complete, which in my case is only once the file has been accessed. I need some way of it running in the background, something like a service?

     
  • Craig Chambers
    Craig Chambers
    2012-03-05

    Daemonise it by calling the script with an ampersand (&) after the command…

    > shutdown_script.sh &

    /Craig

     

  • Anonymous
    2012-03-05

    That sounds promising. Ill give it a go.
    Cheers.

     
  • gharris999
    gharris999
    2012-03-09

    My server runs two services for media: logitech media server for audio and minidlna for video.  I wrote a plugin for LMS that provides power management and automatically suspends the server when content isn't being played.  I extended the plugin a little over a year ago to monitor network io so the server would stay awake while minidlna streamed video.  The perl code for my plugin could probably be adapted to be a general purpose power management daemon.

    For a sense of the code, see: http://code.google.com/p/srvrpowerctrl/source/browse/SrvrPowerCtrl/trunk/Stats.pm

     

  • Anonymous
    2012-03-10

    Thanks for everyone's help on this, I now have a working solution.

    If anyone else is interested here is how it is set up.
    I created the following script:

    #!/bin/sh
    inotifywait -e open /media/Documents/Video/Shutdown.avi | while read FILE
    do
    shutdown -h now
    done

    This uses inotifytools to monitor a dummy avi file in my shared videos folder.

    I put this script in in the /etc/init.d (same place as the minidlna start up script)
    I then modified the minidlna start up script by add the following line in the start case:

    /etc/init.d/Shutdown &

    This now results in the file watching starting with minidlna.

    Again thanks to all.

     
  • HPP8140
    HPP8140
    2014-08-13

    Interesting idea. I've adopted it to restart minidlna so that my poorly implemented Samsung TV will refresh it's media cache.

    inotifywait -m -e access /Refresh.mp4 | while read FILE
    do
    sleep 10
    service minidlna restart
    sleep 2
    done