Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 { } } }

In reply to Re: Unix disk space reports by mr_leisure
in thread Unix disk space reports by halxd2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-03-29 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found