#!/usr/bin/perl -w

=head1 NAME

octo_commander - Octopussy Commander program

=head1 SYNOPSIS

octo_commander 

=head1 DESCRIPTION

octo_commander is the program used by the Octopussy Project to launch command from WebInterface

=cut

use strict;
use warnings;
use Readonly;

use Octopussy;
use Octopussy::Cache;

Readonly my $PROG_NAME => 'octo_commander';

exit if (!Octopussy::Valid_User($PROG_NAME));

my $cache = Octopussy::Cache::Init($PROG_NAME);
while (1)
{
    my $commands = $cache->get('commands');
    $cache->remove('commands');    # TODO If cache set between get & remove ?
    foreach my $c (@{$commands})
    {
        if (my ($command, $args) = $c =~ /^(\/usr\/sbin\/octo_\S+)(.*)/)
        {
            system "$command $args";
        }
    }
    sleep 1;
}

=head1 AUTHOR

Sebastien Thebert <octo.devel@gmail.com>

=head1 SEE ALSO

octo_extractor, octo_parser, octo_uparser, octo_reporter, octo_rrd, 
octo_scheduler

=cut
