#!/usr/local/bin/perl
#
# Run 3cglobalcache in parallel batch mode using xargs
# to update the global bridge table cache
#
# $Id: batch-cacheupdate,v 1.3 1999/06/04 01:46:06 trockij Exp $
use Getopt::Std;

getopts ("dhvAa:s:n:", \%opt);

$SWLIST = "swlist";
$SWLIST = "/home/mis/net/switch-config/switch-list";
$ARPFILE = "/home/mis/net/switch-config/core-routers";

$SWLIST	= $opt{"s"} if ($opt{"s"});
$ARPFILE = $opt{"a"} if ($opt{"a"});

$NUM	= $opt{"n"} || 5;

$XARGS	= "xargs -t -P$NUM -l1 -n1";
$GC	= "./3cglobalcache";

if ($opt{"v"}) {
    $XARGS .= " -t";
}

if ($opt{"d"}) {
    $GC .= " -d";
}

#
# bridge tables
#
if (!$opt{"A"}) {
    open (I, $SWLIST) ||
	die "could not open switch list: $!\n";

    while (<I>) {
	next if (/^\s*#/ || /^\s*$/);
	chomp;
	push @sw, $_;
    }

    close (I);

    open (O, "| $XARGS $GC -b") ||
	die "could not open pipe to xargs: $!\n";

    for (@sw) {
	print O "$_\n";
    }

    close (O);

#
# ARP history table
#
} else {

    system ("$GC -a $ARPFILE");
}
