Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Unix disk space reports

by mr_leisure (Beadle)
on Dec 21, 2000 at 18:42 UTC ( #47787=note: print w/ replies, xml ) Need Help??


in reply to Unix disk space reports

And if you are looking for a graphical representation of df -k running on your specified directory and looping on your specified timescale, using Perl::TK, check my little program out... Cheers ML

------------------------------------------------------------ DISKCHECK.pl ---------------------------- #!/usr/bin/perl # # Simple Diskcheck GUI, running my ds.pl diskcheck script. This GUI d +isplays the results of a diskcheck loop. # # Usage : diskcheck.pl # # # You will need to be running ds.pl -dir=DIRECTORY -time=LOOPTIME at t +he same time as running the GUI. # # # use Tk; use Net::Telnet(); # open filehandle to log file, in this case, ds.txt open (LOG, "tail -f ds.txt|") || "Could not open logfile!\n"; # create main GUI window my $mw = MainWindow->new(); $mw->Label(-text => "DiskCheck Utility for PerlMonk.org Folks")->pack +; # label that window my $menubar = $mw->Frame(-relief => "ridge", -borderwidth => 2)->pack (-anchor => "nw", -fill => "x"); # cr +eate menubar and its properties my $filemenu = $menubar->Menubutton(-text =>"File", -underline => 1)->pack (-side => "left"); # add first menu but +ton : File $filemenu->separator(); # add line separator on menu $filemenu->command(-label => "Save Current Log to DSlog.txt" -command => \&save_yn); # add button : Save log to file $filemenu->separator(); # add line separator on menu $filemenu->command(-label =>"Quit", -command => \&really_quit); # add button : Quit my $optmenu = $menubar->Menubutton(-text => "Options", -underline =>1)->pack (-side => "left"); # add new menu button + : Options $optmenu->separator(); # add line separator on menu $optmenu->command(-label => "Clear Logs", -command => \&clear_log); # add button : Clear Logs $optmenu->separator(); # add line separator my $helpmenu = $menubar->Menubutton(-text => "Help", -underline => 1)->pack (-side => "left"); # add Help menu $helpmenu->separator(); # add line separator to menu $helpmenu->command(-label => "About DiskCheck", -underline =>1, -command => \&help_about); # add about button +pointing to help_about subroutine my $text = $mw->Listbox(-relief => "sunken", -width => 50, -height => +30, -background => "white"); # add main data box my $scroll = $mw->Scrollbar(-command => ["yview", $text]); # add r +ight scrollbar $text->configure(-yscrollcommand => ["set", $scroll]); $text->pack(-side => "left", -fill => "both", -expand => "yes"); $scroll->pack(-side => "right", -fill => "y"); $mw->fileevent(LOG, 'readable', [\&insert_text]); MainLoop; sub insert_text { my $curline; if ($curline = <LOG>) { $text->insert('end', $curline); $text->yview('moveto', 100); } else { $mw->fileevent(LOG, 'readable', ""); } } sub clear_log { $text->delete(0, 'end'); } sub save_log { my @current_log = $text->get(0, 'end'); open (LOG2, ">>DSlog.txt"); print LOG2 @current_log; close (LOG2); exit; } sub save_yn { if (! Exists($sftl)) { my $sftl = $filemenu->Toplevel(); $sftl->title("Alert!"); $sftl->Label(-text => "Save to DSlog.txt? \nWARNING : Destinat +ion file will be overwritten!")->pack; $sftl->Button(-text => "Yes", -command => \&save_log, -command => sub {$sftl->withdraw}) +->pack(-expand => "yes", -side=>"left"); $sftl->Button(-text => "No", -command => sub { $sftl->withdraw })->pack(-expand => "yes +", -side => "right"); } else { $sftl->deiconify(); $sftl->raise(); } } sub not_complete { if (! Exists($omtl)) { my $omtl = $optmenu->Toplevel(); $omtl->title("Alert!"); $omtl->Label(-text =>"This Section Not Complete!")->pack; $omtl->Button(-text => "Ok", -command => sub { $omtl->withdraw })->pack(-expand => "yes +"); } else { $omtl->deiconify(); $omtl->raise(); } } sub help_about { if (! Exists($hmtl)) { my $hmtl = $helpmenu->Toplevel(); $hmtl->title("About DiskCheck"); $hmtl->Label(-justify => center, -text => "Originally written for UBS warburg, by Mr Leisure <mr_le +isure@hotmail.com>" )->pack; $hmtl->Button(-text => "Ok", -command => sub { $hmtl->withdraw } )->pack(-expand => "yes"); } else { $hmtl->deiconify(); $hmtl->raise(); } } sub really_quit { if (! Exists($qbtl)) { my $qbtl = $filemenu->Toplevel(-height=> 20, -width=> 45); $qbtl->title("Alert!"); $qbtl->Label(-text => "Do You Really Want To Quit?")->pack; $qbtl->Button(-text => "Yes", -command => sub {exit})->pack(-side => "left", -expand => "yes +"); $qbtl->Button(-text => "No", -command => sub {$qbtl->withdraw} )->pack(-expand => "yes", -s +ide => "right"); } else { $qbtl->deiconify(); $qbtl->raise(); } } ----------------------------------------- DS.PL ------------------------ #!/usr/bin/perl ###################################################################### +######## # # ds.pl - check diskspace utility on specified directory # # # # usage : ds.pl -dir=/YOURDIR -time=5 # # - will run utility on /YOURDIR directory, looping every 5 + seconds # # # ###################################################################### +######## # use strict; # use English; # use Cwd; # use efSetupEnv; use Getopt::Long; my %opt = (); GetOptions(\%opt, "dir=s", # name of directory to be checked "time=i", # sleep period before restart ); die "Must specify directory!" unless $opt{dir}; die "Must specify interval in seconds!" unless $opt{time}; until (! $opt{time}) { { check_disk_space($opt{dir} ) ; sleep($opt{time}) } sub check_disk_space { my $dfout = `df -k $opt{dir}` || die "Cannot check space on $o +pt{dir}!\n"; $dfout =~ s/ +/ /g; my @space = split (/ / , $dfout); my $block = $space[9]; if ($block < 50000) { # set this to whatever you want open(OUTPUT,">>ds.txt"); print OUTPUT "Error : Only $space[9] blocks free on $opt{dir} +!\n"; close(OUTPUT); } elsif ( $block < 6000000000 ) { #this too open(OUTPUT,">>ds.txt"); print OUTPUT "$space[9] blocks free on $opt{dir}\n"; close (OUTPUT); } else { } } }


Comment on Re: Unix disk space reports
Download Code
Re: Re: Unix disk space reports
by jrajg (Initiate) on Feb 11, 2001 at 07:36 UTC
    Is there a CGI version of this script? I have written a CGI script for process monitoring on several servers.. and this would come in handy! A quick question.. I have used remsh instead of Net::Telnet module to access the remote servers, and I am aware of its security pitfalls as it uses .rhosts. What do you think?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://47787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-21 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls