Advertisement
mightyroot

Cacti query unix partition

Apr 30th, 2012
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.46 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. if (($ARGV[0] ne "query") && ($ARGV[0] ne "get") && ($ARGV[0] ne "index") && ($ARGV[0] ne "num_indexes")) {
  4.         print "usage:\n\n";
  5.         print "./query_unix_partitions.pl index\n";
  6.         print "./query_unix_partitions.pl num_indexes\n";
  7.         print "./query_unix_partitions.pl query {device,mount,total,used,available,percent}\n";
  8.         print "./query_unix_partitions.pl get {device,mount,total,used,available,percent} DEVICE\n";
  9.         exit;
  10. }
  11.  
  12. open(DF, "/bin/df -P -k|");
  13.  
  14. $count=0;
  15. while (<DF>) {
  16.         #/dev/hda2             20157744  18553884    579860  97% /var
  17.         if (/^(\/\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(\/\S*)$/) {
  18.                 my %output = (
  19.                         device => $1,
  20.                         mount => $6,
  21.                         total => $2,
  22.                         used => $3,
  23.                         available => $4,
  24.                         percent => $5
  25.                 );
  26.  
  27.                 if ($ARGV[0] eq "index") {
  28.                         print "$1\n";
  29.                 }elsif ($ARGV[0] eq "num_indexes") {
  30.                         $count++;
  31.                 }elsif (($ARGV[0] eq "get") && ($ARGV[2] eq $1)) {
  32.                         print $output{$ARGV[1]};
  33.                 }elsif ($ARGV[0] eq "query") {
  34.                         print "$output{device}:$output{$ARGV[1]}\n";
  35.                 }
  36.         }
  37. }
  38.  
  39. close(DF);
  40.  
  41. if ($ARGV[0] eq "num_indexes") {
  42.         print "$count\n";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement