Networker

[Networker] nsradmin and perl snippets

2005-08-04 05:57:37
Subject: [Networker] nsradmin and perl snippets
From: "Maarten Boot (CWEU-USERS/CWNL)" <Maarten.Boot AT NL.COMPUWARE DOT COM>
To: NETWORKER AT LISTSERV.TEMPLE DOT EDU
Date: Thu, 4 Aug 2005 11:59:53 +0200
my $QUERY_STATE = "";
my @QUERY_RESULT = ();

sub do_nsradmin2 ($$@)
{
    my $pr = shift;
    my $sep = shift;
    my (@a) = @_;

    my $tmpf="/tmp/_tmp.$$";

    open( TMPF, ">$tmpf") || die "FATAL: cannot open '$tmpf' , $!";
    print TMPF join($sep,@a) , "\n";
    close TMPF;

    @QUERY_RESULT = ();
    $QUERY_STATE = "";

    my $NSRADMIN="/usr/sbin/nsradmin";
    open(PIPE,"$NSRADMIN -i $tmpf |") || return 1;

    while(<PIPE>) {
        chop;

        next if /current query set/i;
        if( /no resources to delete!/i ) { $QUERY_STATE = "NOTFOUND"; last; }
        if( /no resources found for query/i ) { $QUERY_STATE = "NOTFOUND"; 
last; }

        s/^\s+//;
        s/\s+$//;
        s/\\$//;

        next if /^$/;

        push(@QUERY_RESULT,$_);
        $QUERY_STATE = "OK";

        print_dos $_ if ($pr);
    }
    close PIPE;

    unlink $tmpf if ( -e $tmpf);
    if( $QUERY_STATE eq "OK" ) {
        return 0;
    }
    return 1;
}

sub group_stop ($)
{
    my $group = shift;

    my @a = (
        ". type: NSR group; name: $group",
        "update Stop now: True",
    );

    &do_nsradmin2("", "\n", @a);
}

sub group_start ($)
{
    my $group = shift;

    my @a = (
        ". type: NSR group; name: $group",
        "update autostart:Start now",
    );

    &do_nsradmin2("", "\n", @a);
}

sub group_test_running ($)
{
    my $group = shift;
    my $ret = "UNKNOWN";

    my @a = (
        ". type:NSR group;name:$group",
        "show status",
        "print",
    );

    my $tmpf="/tmp/CLIENT.mk.group.nsr.$$";
    open( TMPF, ">" . $tmpf) || die "FATAL:cannot open: '$tmpf',$!";
    print TMPF join("\n",@a) , "\n";
    close TMPF;

    my $NSRADMIN="/usr/sbin/nsradmin";
    open(IN,"/usr/sbin/nsradmin -i $tmpf |") || die "FATAL: cannot start 
NSRADMIN,$!";
    while(<IN>) {
        chop;
        if( /idle/ )    { $ret = "idle"; last; }
        if( /running/ ) { $ret = "running"; last; }
    }
    close IN;
    unlink $tmpf if ( -e $tmpf);

    return $ret;
}

--
Note: To sign off this list, send a "signoff networker" command via email
to listserv AT listserv.temple DOT edu or visit the list's Web site at
http://listserv.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

<Prev in Thread] Current Thread [Next in Thread>