Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Update to DiskCheck GUI

by mr_leisure (Beadle)
on Dec 21, 2000 at 22:28 UTC ( #47851=CUFP: print w/replies, xml ) Need Help??

Updated my diskcheck stuff so now we can call the GU.pl straight from the command line ds.pl entry...
#!/sbcimp/run/pkgs/gsbl/bin/perl ###################################################################### +######## # # ds.pl - check diskspace utility on specified directory # # # # usage : ds.pl -dir=/global1 -time=5 -error=50000 # # - will run utility on /global1 directory, looping every 5 + seconds. If # diskspace free drops below 50000, an error message will be printe +d to the # logfile (ds.txt) and sent via SMS to the mobile numbers assigned in +call_sms_zh.pl # # # ###################################################################### +######## # 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 "error=i", # enter threshold for error message "gui!", # do you want to show the logfile in the GUI ); die "Must specify directory!" unless $opt{dir}; die "Must specify interval in seconds!" unless $opt{time}; die "Must specify a minmum diskspace threshold!" unless $opt{error}; if ($opt{gui}) { my $pid = call_gui(); exit if ($pid==0); } 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 < $opt{error}) { open(OUTPUT,">>ds.txt"); my $error = "\"Error : Only $space[9] blocks free on $opt{dir} +!\n\""; print OUTPUT "Error : Only $space[9] blocks free on $opt{dir} +!\n"; exec("call_sms_zh.pl -msg=$error"); close(OUTPUT); } elsif ( $block < 600000000 ) { open(OUTPUT,">>ds.txt"); print OUTPUT "$space[9] blocks free on $opt{dir}...\n"; close (OUTPUT); } else { } } sub call_gui { my $pid; if ($pid = fork()){ # parent process } elsif (defined $pid){ # if defined pid is 0, therefore this is the child exec("GU.pl"); } else { $pid = 0; } return $pid; } }
And the Gui...
#!/sbcimp/run/pkgs/gsbl/bin/perl #!/sbclocal/bin/perl # # need to look at restarting the program, whilst keeping the GUI alive +. This would mean you don't have to # start ds.pl before you start GlobalUtility.pl for it to work - i.e. +read the logfile thru the filehandle # 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 => "GlobalUtility for Global 1")->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 GUlog.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 #$optmenu->command(-label => "Send SMS...", #-underline => 1, -command => \&send_sms); # add SMS button - will + point towards SMS subroutine $optmenu->separator(); # add line separator $optmenu->command(-label => "Send Mail...", -underline =>1, -command => \&send_mail); #add mail button 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 GlobalUtility", -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, ">>GUlog.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 GUlog.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 GlobalUtility"); $hmtl->Label(-justify => center, -text => "Global Utility for Global One\nThis program has been cal +led by the ds.pl script, and the ds.txt logfile. author : herberja\nlast major revision : 21 Dec 2000\n")->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(); } } # At some point, i would like to have a sub that constantly searches t +he listbox for the line with the word "Error:" in it. # When it finds one, it will fire off an SMS to whichever support mobi +le is designate, using $text->get("error") or whatever #sub send_sms_box #{ #if (! Exists($smstl)) { # my $smsframe = $mw->Toplevel(); # $smsframe->title("Manual SMS Tool - Testing Purposes Only +"); # $smsframe->Button(-text => "Send", # -command => \&send_sms, -command=>sub {$smsframe->wi +thdraw} )->pack(-expand => "yes", -side => "bottom", -anchor => "s"); # } # else { # # $smsframe->deiconify(); # $smsframe->raise(); # } # } sub send_sms { my $lastline = $text->get(0); exec("call_sms_zh.pl -msg=$lastline"); } sub send_mail { my $lastline = $text->get(0); open (MAIL,"| /usr/ucb/mail -s Update_From_G1 james.herbe +rt"); print MAIL "$lastline"; close MAIL; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://47851]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-09-27 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?