"Fossies" - the Fresh Open Source Software Archive

Member "unix/Darwin/dmg/files/pandorafms/inst_utilities/print_conf.pl" (15 Sep 2021, 644 Bytes) of package /linux/misc/pandorafms_agent_unix-7.0NG.757.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env perl
    2 
    3 use strict;
    4 
    5 my ($CONF_FILE, $token, $value) = @ARGV;
    6 exit unless defined ($value);
    7 exit unless -e $CONF_FILE;
    8 
    9 open(my $fh, '<', $CONF_FILE) or die($!);
   10 my @lines = <$fh>;
   11 close ($fh);
   12 
   13 # Set the new value for the configuration token.
   14 my $found = 0;
   15 for(my $i = 0; $i < $#lines; $i++) {
   16     if ($lines[$i] =~ m/[#\s]*$token/) {
   17         $lines[$i] = "$token $value\n";
   18         $found = 1;
   19         last;
   20     }
   21 }
   22 
   23 # Append the token to the end if it was not found in the file.
   24 if ($found == 0) {
   25     push(@lines, "$token $value\n");
   26 }
   27 
   28 # Write the changes to the configuration file.
   29 open($fh, '>', $CONF_FILE) or die($!);
   30 print $fh @lines;
   31 close($fh);