-----Ursprüngliche Nachricht-----
Von: Andrew Best [mailto:[EMAIL PROTECTED] 
Gesendet: Donnerstag, 16. September 2004 05:40
An: [EMAIL PROTECTED]
Betreff: [mrtg] wrapping around cfgmaker


Afternoon,

Im wanting to build a frontend for an MRTG setup that will let me
add/delete hosts to the configs.
Pretty simple thing to do except for the fact that cfgmaker insists on
putting un-needed entries in the output it produces. Things like:

> ### Global Config Options
> 
> #  for UNIX
> # WorkDir: /home/http/mrtg
> 
> #  or for NT
> # WorkDir: c:\mrtgdata
> 
> ### Global Defaults
> 
> #  to get bits instead of bytes and graphs growing to the right
> # Options[_]: growright, bits
> 
> EnableIPv6: no

I really dont want this guff generated since its already contained in
the main config file ill be adding the host to.

Ive looked through the docs for cfgmaker to do with templates etc but
cant see anything thats going to let me supress this output.

Anyone point me in the right direction?


I try to write a perl-script for making *.cfg-files for Standard-W2k-server.
One point is including the output of cfgmaker. So I read the output and
delete all lines with a # or ; or SPACE or < and write the rest in the
config-file.

..........some stuff making a my own head on the *cfg-file

#----------------------------------------------------------------------
#  Ausführen von cfgmaker. Von cfgmaker erstellte Kommentarzeilen und 
#  Leerzeilen werden nicht übernommen. Vor jedem neuem Netzdeviceabsatz 
#  wird ein Kopf eingefügt.
#----------------------------------------------------------------------

open CFGMAKER, "cfgmaker $community"."\@"."$host |";
while (<CFGMAKER>) 
        {
        $string = $_;
        &nodoc;                 # <--- delete all unnessasary lines, see
bottom
        if (substr($string,0,6) eq "Target") 
                {
                print CFGDATEI
"#---------------------------------------------------------------\n";
                print CFGDATEI "#Netzdevice \n";
                print CFGDATEI
"#---------------------------------------------------------------\n\n";
                }
        if (substr($string,0,1) ne "<")
                {
                print CFGDATEI $string;
                }
        }
close CFGMAKER;

......... More stuff

This is the sub named nodoc:

#################################################################
# Die Funktion erwartet eine Zeichenkette in $string und 
# gibt diese nur zurück sofern dies keine Leerzeile und
# keine Zeile mit Hash (#) oder ; am Beginn ist, Leerzeichen am 
# Anfang einer Zeile entfernt werden.
#
# Version 1.0  -  16.12.2002
#
# Rainer Kulhanek Oktober 2002 [EMAIL PROTECTED]
#################################################################

sub nodoc
{
        $my_string = $string;
#---------------------------------------------------------------------
# Finde erstes Zeichen
#---------------------------------------------------------------------
        $my_char = (substr $my_string,0,1);
#---------------------------------------------------------------------  #x
# Wenn erstes Zeichen ein Leerzeichen oder ein TAB dann Zeile um dieses #x
# Zeichen kürzen; solange bis erstes Zeichen kein Leerzeichen ist
#x
#---------------------------------------------------------------------  #x 

        while ($my_char eq " " or $my_char eq "\t")
#x
                {
#x
                $my_string = (substr $my_string,1);
#x
                $my_char = (substr $my_string,0,1);
#x
                }
#---------------------------------------------------------------------
# Zeilen deren erstes no_whitespace_Zeichen ein # oder ; ist, übergehen
#---------------------------------------------------------------------
        
        if ($my_char ne "#" and $my_char ne "\n")
                {
                $string = "$my_string";
                }
        else
                {
                $string="";
                }
}


Both are not the art of good code, but it works. The sub is from another
projekt, so the sense of lines marked with #x should included in the lines
follow later.


Rainer

--
Unsubscribe mailto:[EMAIL PROTECTED]
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

Reply via email to