Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Run Plugins from Command Line?

Quote Reply
Run Plugins from Command Line?
Can I run a plugin from the command line (SSH)?

I know I would have to hard-code variables that might come from a form or whatever into the .pm file.
Quote Reply
Re: [CrazyGuy] Run Plugins from Command Line? In reply to
What you need to do is write a .cgi script to execute via SSH. You need something like this at the top;

Code:
#!/usr/local/bin/perl

use strict;
use lib '/full/path/to/admin/folder';
use Links qw/$IN $DB $CFG $USER/;

use CGI::Carp qw(fatalsToBrowser);


local $SIG{__DIE__} = \&Links::fatal;

my ($url, $hit, $opts);

Links::init('/full/path/to/admin/folder');
Links::init_user();
$opts = Links::Plugins->get_plugin_user_cfg('Plugin_Name');
my $hitfield = $opts->{'Setting_Name1'};
my $urlfield = $opts->{'Setting_Name2'};

# do your stuff here :)


Then you can run it via SSH/Telnet simply with;

perl scriptname.cgi

Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Run Plugins from Command Line? In reply to
I know, I know, ... dredging this up after almost 2 years !

... but it seemed too complex at the time for what I wanted to do.

Now it doesn't seem so complex ... mainly because I suspect I really, really need to work something out. But I still don't understand objects in Perl, or the plugin architecture, so ...

For example ... let's say I have a PLUGIN called "MIRACLE". Normally this would be run from a web interface containing a form that supplies the plugin with the contents of two form fields called "VARIABLE1" and "VARIABLE2".

How would I structure a wrapper script to run that plugin via SSH?

"VARIABLE1" and "VARIABLE2" will always be the same values, so I can hard-code them into the wrapper script.

When you say "do your stuff here" - do you mean that's where the plugin would be run (how?) or are you allowing for some other pre/post processing?

Sorry for coming back to this - but having dug through the plugin script etc I'm still not really any wiser as to the flow of all this.

Thanks again for your help :)

CG
Quote Reply
Re: [CrazyGuy] Run Plugins from Command Line? In reply to
Hi,

It sounds like you may need to play with some small pluigns, to see how they do it. Unfortunatly, its not exactly something you can put together in one post =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [CrazyGuy] Run Plugins from Command Line? In reply to
Do you really need a plugin? You might just need to write a to handle the form.
If you can give more information about what you are trying to do it will be easier to help you.
Quote Reply
Re: [Andy] Run Plugins from Command Line? In reply to
OK - following the trail back through the code, I have sledgehammer solved my problem by hacking a copy of admin.cgi specifically to run a modified version of the plugin with the variables all hardcoded in. That hacked admin.cgi can then be run from SSH. Crude, but it works :)
Quote Reply
Re: [CrazyGuy] Run Plugins from Command Line? In reply to
Hi,

Sorry, didn't re-read your first post. You could do this with (in SSH);

cd /path/to/admin
perl admin.cgi 'do=plugin&plugin=Plugin_Name&func=FunctionToRun'

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Run Plugins from Command Line? In reply to
 
Quote:

cd /path/to/admin
perl admin.cgi 'do=plugin&plugin=Plugin_Name&func=FunctionToRun'

That's actually very useful - in general - as I've never known how to run a script with parameters like that. Thanks!

And yes, it should work for what I was trying to do too, as I had worked out everything that admin needed passed to it, I just wasn't trying the right syntax to run script + parameters on the command line.


Quote Reply
Re: [CrazyGuy] Run Plugins from Command Line? In reply to
Hi,

No worries. I was only shown how to use that by Adrian a little while back <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!