PDA

View Full Version : Executing scripts on server events...



deggy
2010-02-15, 02:30
Hi,

I would like to try to execute a script on server events (changing tracks from the web 'status' page for example. One of my players has a large cache; I can flush it via a simple network operation and I want to be able to do this whenever I change tracks on my servers web front end.

I have tried modding the Web/HTTP.pm, and modifying the processURL function to execute a script on a particular URL patten



if ( $p[$i] == "jump" )
{
@args = ("/usr/bin/testscript.pl");
system(@args) == 0;
#system "/usr/bin/testscript.pl";
}


for example, which sort-of works, but the script seems to execute at random intervals regardless of interactions with the front-end, and this seems like too much of a hack!

Does anyone who knows the server code well have a suggestion for where I could implement this feature?

erland
2010-02-15, 10:34
Search for the ExecuteScript plugin, it sounds like it will be able to do pretty much exactly what you want. It can be installed through the Plugins tab in the settings page of Squeezebox Server.

deggy
2010-02-15, 14:43
Search for the ExecuteScript plugin, it sounds like it will be able to do pretty much exactly what you want. It can be installed through the Plugins tab in the settings page of Squeezebox Server.

Thanks for the advice - I have already tried that plugin, but it's a little basic.

What I really want to be able to do is to have a script executed (via fork() or system()) which takes inputs like the selected player URL. This script would then, based on the URL perform a number of actions (for instance, commanding the player to flush its cache).

I'm pretty happy with how I would write this - it's just where best to call it that has me stumped. The Squeezebox Server code is pretty complex, particularly when you start playing with the web-based frontend, and I'm pretty sure that Web/HTTP.pm is not the place to put the function (any advice)?

peterw
2010-02-15, 15:23
1) I think you should better describe what you want to achieve. Do you really only want this to work if somebody has a web browser open?
2) Modifying core SBS .pm code sounds like the wrong way to go. I suspect you should make a plugin that subscribes to certain types of notifications. Or an external app that connects to the CLI port and subscribes to notifications.

mherger
2010-02-15, 22:36
> Thanks for the advice - I have already tried that plugin, but it's a
> little basic.

But it would show you how to subscribe to events and trigger actions on it. No need to modify core code.

--

Michael

deggy
2010-02-25, 14:28
> Thanks for the advice - I have already tried that plugin, but it's a
> little basic.

But it would show you how to subscribe to events and trigger actions on it. No need to modify core code.

--

Michael

I have tried to look at this - the site hosting the plugin dissapeared some time ago. The Internet Archive revealed a copy of the source at google code but it's in some form of Perl archive (par) format. Does anyone know how to extract this easily?

Dan

Grotus
2010-02-25, 17:04
On Feb 25, 2010, at 1:28 PM, deggy wrote:
> I have tried to look at this - the site hosting the plugin dissapeared
> some time ago. The Internet Archive revealed a copy of the source at
> google code but it's in some form of Perl archive (par) format. Does
> anyone know how to extract this easily?

PAR, like JAR, is a fancy name for ZIP. Anything that can open
a .zip file can open a .par, you may need to rename the file with
a .zip extension to convince the utility of that though.