#!/usr/bin/perl
use vars;
$file = "/home/gds/navcsStatus";
if (!open (FILE, $file)) {
print "ERROR: Status file not found : $file";
exit(0);
}
#$new_file = "./vcsstatus.php";
#if (-e $new_file) {
# unlink($new_file);
#}
$stat_line = '';
$Name = '';
$Value = '';
$val_name = '';
$val_status = '';
$val_zone_num = '';
while(<FILE>) {
my($line) = $_;
chomp($line); # Get rid of the traillingtrailing \n
$line =~ s/^\s*//; # Remove spaces at the start of the line
$line =~ s/\s*$//; # Remove spaces at the end of the line
if ( ($line !~ /^#/) && ($line ne "") ){ # Ignore lines starting with # and blank lines
($Name, $Value) = split (/:/, $line); # Split each line into name value pairs
if( ($Name eq "Name") or ($Name eq "Status") or ($Name =~ m/^Zone*/)){ # Checks to see if $Name is Name or Status
$Value =~ s/^\s*//; # Removes spaces from the start of the value
$Value =~ s/\s*$//; # Removes spaces from the end of the value
if($Name =~ m/^Zone\s*/){ # Searches for the line that starts with "Zone X"
my($z_zone, $z_number); # Defines local variables for parsing and seperatingseparating Zone and X
$Name =~ s/^\s*//; # Removes extra space from beginning
$Name =~ s/\s*$//; # Removes extra space from the end
$Name =~ s/[:]*$//; # Removes the : fronfrom the end of "Zone X:"
($z_zone, $z_number) = split (/\s/,$Name); # Splits "Zone X" into "Zone" and "X"
$val_zone_num = $z_number; # Assigns "X" to variable $val_zone_num
}
if($Name eq "Name"){ #Checks for what the name of the line is, if it is "Name", it continutescontinues
$Value =~ s/^["]*//; # Removes quotes from beginning of Name
$Value =~ s/["]*$//; # Removes quotes from end of Name
$val_name = $Value; # Assigned the name of the zone to $val_name
}
if($Name eq "Status"){ #Checks for what the name of the line is. It is "Status", it contintuescontinues
$val_status = $Value; #Assigned the value of "Status" otof $val_status
}
if( ($val_name ne '') && ($val_status ne '') ){ #Since it cycles through the lines a few times before it gets to the next variable, it checks to see if both Name and Status have values applies (IE not empty), If both values have values assigned, it continues in. If not, it goes to the next line retraining any value that has been assiendassigned to either $val_name or $val_status.
$stat_line .= "$val_zone_num:$val_name:$val_status\r\n"; # write the line giving the name and status of the zone. Output will look like: XXX: Zone_name: Status. IE: 1: Some_Zone: Active
$val_name = ''; # Clears out the variblevariable for next loop through.
$val_status = ''; # Clears out the variable for the next loop through
}
}
}
if($line eq "*s/end"){
last;
}
}
close FILE; # Closes the input file it read from.
open FILE2, ">/home/gds/vcs_scripts/vcsstatus.cfg" or die $!; #Opens the file 'vcsstatus.php' for writing to.
print FILE2 $stat_line; # writes the value of $stat_line to the file
close FILE2; # Closes the file. |