#! /usr/bin/perl

$WIF_CMD_FILE = "/tmp/cli/wif_cmd.$$";

# Open the command pipe
open IOSCLI, "/opt/meru/bin/ioscli -c \"show interfaces Dot11Radio\" |" or die "Cannot run \"show interfaces Dot11Radio\".";

# Delete the file if existed
unlink $WIF_CMD_FILE or die "Cannot delete the existing WIF command file\n" if -e "$WIF_CMD_FILE";
open CMD_OUTFILE, ">$WIF_CMD_FILE" or die "Can not create WIF command file: $!\n";

# skip the headers
scalar <$IOSCLI>;
scalar <$IOSCLI>;
scalar <$IOSCLI>;

# Write AP command into scripts file
while (<IOSCLI>)  {
    chomp;
    
    # skip blank lines
    next if !/^(\d+)\s+(\S+)\s+(\S+)s*/;    
    my ($wifid, $radio) = ($1, $3);

    next if !defined $wifid;
    next if !defined $radio;

    print CMD_OUTFILE "show interfaces Dot11Radio $wifid $radio\n";
    #print "-- WIF: $wifid $radio \n";
}

# Close the AP command file
close CMD_OUTFILE;

# Close the WIF command file
close IOSCLI;

# Run the command scripts file
system  "/opt/meru/bin/ioscli -f $WIF_CMD_FILE";

# Remove the command script file
unlink $WIF_CMD_FILE or die "Cannot delete WIF command file\n";

