Problem mit Input-File

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Problem mit Input-File

    Hallo Community

    Ich habe folgendes Input-File:
    Code:
      08:20AM   up 26 days,  12:36,  1 user,  load average: 1.70, 1.48, 1.46
    device              maj,min        total       free
    /dev/hd6              10,  2      9984MB      9385MB
    Filesystem    GB blocks      Used      Free %Used Mounted on
    /dev/hd4           1.00      0.02      0.98    2% /
    /dev/hd2           2.00      1.66      0.34   84% /usr
    /dev/hd9var        2.00      0.03      1.97    2% /var
    /dev/hd3           3.00      0.05      2.95    2% /tmp
    /dev/hd1           1.00      0.00      1.00    1% /home
    /proc                 -         -         -    -  /proc
    /dev/hd10opt       1.00      0.06      0.94    6% /opt
    5300-05-02
    The current permanent system firmware image is SF240_284
    The current temporary system firmware image is SF240_284
    The system is currently booted from the temporary firmware image.
    Dabei würde ich diese Dinge gerne in etwa so formatieren:
    Code:
    Uptime: 08:20AM   up 26 days,  12:36,  1 user,  load average: 1.70, 1.48, 1.46
    SWAP: device              maj,min        total       free
    SWAP: /dev/hd6              10,  2      9984MB      9385MB
    Filesystem: Filesystem    GB blocks      Used      Free %Used Mounted on
    Filesystem: /dev/hd4           1.00      0.02      0.98    2% /
    Filesystem: /dev/hd2           2.00      1.66      0.34   84% /usr
    Filesystem: /dev/hd9var        2.00      0.03      1.97    2% /var
    Filesystem: /dev/hd3           3.00      0.05      2.95    2% /tmp
    Filesystem: /dev/hd1           1.00      0.00      1.00    1% /home
    Filesystem: /proc                 -         -         -    -  /proc
    Filesystem: /dev/hd10opt       1.00      0.06      0.94    6% /opt
    OSLEVEL: 5300-05-02
    OSLEVEL: The current permanent system firmware image is SF240_284
    OSLEVEL: The current temporary system firmware image is SF240_284
    OSLEVEL: The system is currently booted from the temporary firmware image.
    Wie gehe ich da am besten vor? Beachtet bitte, dass das ganze File eigentlich dynmaisch sein kann (also einmal mehr Partitionen, einmal weniger, einmal mehr SWAP-Partitionen, einmal weniger...

    Irgendeine Idee? Ich komme einfach nicht weiter...

  • #2
    Code:
    read Zeile; // 1.
    echo Zeile;
    read Zeile; // 2.
    if Zeile beginnt mit /device {
        do {
            echo SWAP: Zeile;
            read Zeile;
        } while Zeile beginnt mit /;
    }
    if Zeile beginnt mit Filesystem {
        do {
            echo Filesystem: Zeile;
            read Zeile;
        } while Zeile beginnt mit /;
    }
    while read Zeile {
        echo OSLEVEL: Zeile;
    }

    Kommentar


    • #3
      Hallo

      Besten Dank dafür.

      Sieht nun so aus:
      PHP-Code:
      if (file_exists($infilepath))
                  {
                      
      fwrite($outfile,"Uptime: ".$infile[0]);
                      
      fwrite($outfile,"SWAP: ".$infile[1]);
                      
      fwrite($outfile,"SWAP: ".$infile[2]);
                      if (
      preg_match("/\//",substr($infile[3],0,1)))
                      {
                          while(
      preg_match("/\//",substr($infile[3],0,1)))
                          {
                              
      fwrite($outfile,"SWAP: ".$infile[3]);
                              
      $count++;
                          }
                      }
                      if (
      preg_match("/Filesystem/",$infile[$count+3]))
                      {
                          
      fwrite($outfile,"Filesystem: ".$infile[$count+3]);
                          
                          while(
      preg_match("/\//",substr($infile[$count+4],0,1)))
                          {
                              
      fwrite($outfile,"Filesystem: ".$infile[$count+4]);
                              
      $count++;
                          }
                      }
                      
                      for(
      $a=1;$a <= 4;$a++)
                      {
                          
      fwrite($outfile,"OSLEVEL: ".$infile[$count+4]);
                          
      $count++;
                      }
                  } 

      Kommentar

      Lädt...
      X