SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 29th, 2000, 06:20 PM
E. Watson E. Watson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 0 E. Watson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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).]

Reply With Quote
  #2  
Old October 29th, 2000, 08:06 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>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).]

Reply With Quote
  #3  
Old October 29th, 2000, 10:19 PM
E. Watson E. Watson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 0 E. Watson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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).]

Reply With Quote
  #4  
Old October 29th, 2000, 11:19 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Need help placing df -k output to clean HTML table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway