#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    I am trying to write a script that will run from cron (not all of the boxes have web servers, so I am going to push them to a box that does) and produce a web page that will give myself and those I work with an easy means for detecting a problem. What I am getting hung up on is separating the output of 'df -k'. Ultimately what I want to do is break it into a HTML table with 5 columns. Partition, Device info, Space Used, Total space in Kilobytes, and Percentage used. If disk space is < 60% the table row will stay green, elsif disk space < 90% the table row will turn yellow, else table row background is red indicating critical disk usage. I have been running my script one step at a time, and haven't been able to get the output of the df -k command into separate variables in the way I need them. I have been reading and re-reading the split command and associative arrays and hashes, however, my brain is about to explode, I have been at this for a couple of days now. I can't for the life of me, get it to split into the different variables. I have been using two spaces / / in an attempt to delimit them by that means into columns. Once I get that accomplished, I still have to get sort the data in the last column and seperate that into variables as well.

    df -k produces an output similar to the following (Please ignore the periods(.) had to use them to format the output here in this post so you could get an idea of how it appears:

    /..../dev/vg00/lvol13...) :...75359 total allocated kb
    .....................................25000 free allocated kb
    .....................................50359 used allocated kb
    .....................................30 % allocated used

    That is just one partition, more partitions follow, i.e. /var, /usr, /data and such.

    Any help would be greatly appreciated. Thank you for you time.

    The following is an example of the appearance of the table I am trying accomplish. http://www.dakotaglory.com/example.html


    [This message has been edited by E. Watson (edited October 29, 2000).]
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>The following is an example of the appearance of the table I am trying accomplish

    I haven't checked that out, you are on your own to design the appearance. The following ready-to-run script should give you some ideas:

    #############################################
    #!/usr/local/bin/perl

    # Use either -h or -k flag or leave it blank for default (-k)
    # -h for human-readable size output
    # -k for 1k-block output
    $flag = "";
    @df = `df $flag`;

    print "Content-type: text/htmlnn";
    print "<table border=2>n";
    print "<tr>n";
    print "<td><b>Filesystem</b></td>n";
    if ($flag eq "-h") {
    print "<td><b>Size</b></td>n";
    }
    else {
    print "<td><b>1k-blocks</b></td>n";
    }
    print "<td><b>Used</b></td>n";
    print "<td><b>Avail</b></td>n";
    print "<td><b>Capacity</b></td>n";
    print "<td><b>Mounted on</b></td>n";
    print "</tr>n";

    foreach $line (@df) {
    next if ($line =~ /Filesystem/);
    ($fsystem,$blocks,$used,$avail,$capacity,$mounted) = split(/s+/,$line);
    ($number,$sign) = split(/%/,$capacity);
    if ($number < 60) {
    print "<tr bgcolor=green>n";
    }
    elsif (($number >= 60) && ($number < 90)) {
    print "<tr bgcolor=yellow>n";
    }
    else {
    print "<tr bgcolor=red>n";
    }
    print "<td>$fsystem</td>n";
    print "<td>$blocks</td>n";
    print "<td>$used</td>n";
    print "<td>$avail</td>n";
    print "<td>$capacity</td>n";
    print "<td>$mounted</td>n";
    print "</tr>n";
    }
    print "</table>n";
    #############################################

    [This message has been edited by freebsd (edited October 29, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    freebsd,
    I am not at work right now, however, I am working on rebuilding my Linux box tonight. Just got back from Middle East (Navy) and have had problems due to the move. Regardless of that, I really appreciate you responding to my post. This will help us out tremendously if it works. Either way, it's a great help. I didn't even consider

    ($fsystem,$blocks,$used,$avail,$capacity,$mounted) = split(/s+/,$line);

    I was stuck on @array = split(/s+/,$line);

    After a couple of days of reading through the book my brain started getting tunnel vision. Again, I can't thank you enough. I don't get much traffic, and it isn't much, however, if you have a website I will gladly put your link on my site. Just want to return the favor.

    Very Respectfully,
    E. Watson



    [This message has been edited by E. Watson (edited October 29, 2000).]
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>This will help us out tremendously if it works

    It will work.

    If you want to use other flag, just add the appropriate line like "if ($flag eq "-h") {" but it's less important.

    >>if you have a website I will gladly put your link on my site

    Thank you for you great offer but I would like to remain anonymous and that's okay, you don't need to return me a favor.

IMN logo majestic logo threadwatch logo seochat tools logo