#!/usr/bin/perl # # #use strict; use Tk; use Tk::Scrollbar; use Tk::Text::SuperText; my $check_dir="/home/Kevin/Desktop/ip"; my $spam_dir="/home/Kevin/Desktop/spam"; my $i=0; my $w=new MainWindow; $w->geometry('300x450'); $w->geometry('+0+0'); $w->title("Kevin's Script Control Center"); #$w->Label(-text=>"Kevin's Script Control Center")->pack; my $see_list=$w->Button(-text=>'See Deleted List', -command => sub{&see_list}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $open_curr=$w->Button(-text=>'Open Current Deleted', -command => sub{&open_curr}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $quit=$w->Button(-text=> 'Quit', -command => sub{exit}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $start_check=$w->Button(-text=> 'Start', -command=>sub{&start_check}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $stop_check=$w->Button(-text=> 'Stop', -command=>sub{&stop_check}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $start_email=$w->Button(-text=> 'Start', -command=>sub{&start_email}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $stop_email=$w->Button(-text=> 'Stop', -command=>sub{&stop_email}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red'); my $status_check=$w->Button(-text=> 'NO STATUS', -fg=>'black', -bg=>'yellow', -activebackground=>'yellow', -activeforeground=>'black'); my $status_email=$w->Button(-text=> 'NO STATUS', -fg=>'black', -bg=>'yellow', -activebackground=>'yellow', -activeforeground=>'black'); my $email_label=$w->Label(-text=>'EMAIL.PL'); my $check_label=$w->Label(-text=>'CHECK.PL'); $w->repeat(1000,sub{&status_check}); $see_list->place(-x=>90,-y=>360); $open_curr->place(-x=>75,-y=>390); $check_label->place(-x=>125,-y=>25); $email_label->place(-x=>125,-y=>90); $status_email->place(-x=>125,-y=>120); $stop_email->place(-x=>220,-y=>120); $start_email->place(-x=>30,-y=>120); $status_check->place(-x=>125,-y=>60); $start_check->place(-x=>30,-y=>60); $stop_check->place(-x=>220,-y=>60); $quit->place(-x=>125,-y=>425); &MainLoop; sub status_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl +/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/2\ +s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$check=1;} } if (($check)==1) { $status_check->configure(-bg=>'green', -activebackground=>'green', -text=>'UP'); } else { $status_check->configure(-bg=>'red', -activebackground=>'red', -text=>'DOWN'); } my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email. +pl/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/ +2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl/)) {$email=1;} } if (($email)==1) { $status_email->configure(-bg=>'green', -activebackground=>'green', -text=>'UP'); } else { $status_email->configure(-bg=>'red', -activebackground=>'red', -text=>'DOWN'); } undef($email); undef($check); } sub start_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl +/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/2\ +s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$already=1;} } if ($already!=1) {system("perl $check_dir/check.pl &");} undef($already); } sub stop_check { my @temp=`ps -ef | grep check.pl`; foreach (@temp) { if (($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2} +\s+pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check. +pl/)||($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts +\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/ip\/check.pl/)) {$pid=$1;} } if (defined($pid)){system("kill -9 $pid");} undef($pid); } sub start_email { my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2}\s ++pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email. +pl/)||($_=~/^kevin\s+\d{1,5}\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+pts\/ +2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl/)) {$already=1;} } if ($already!=1) {system("perl $spam_dir/email.pl &");} undef($already); } sub stop_email { my @temp=`ps -ef | grep email.pl`; foreach (@temp) { if (($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\d{2}:\d{2} +\s+pts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/emai +l.pl/)||($_=~/^kevin\s+(\d{1,5})\s+\d{1,5}\s+\d{1,5}\s+\D{3}\d{2}\s+p +ts\/2\s+\d{2}:\d{2}:\d{2} perl \/home\/Kevin\/Desktop\/spam\/email.pl +/)) {$pid=$1;} } if (defined($pid)){system("kill -9 $pid");} undef($pid); } sub open_curr { @right_now=gmtime(); $curr_doy=$right_now[7]+1; $filename="$spam_dir/deleted.$curr_doy"; my $new=$w->Toplevel; $new->title("Current Deleted List"); $open_curr=$new->Scrolled("Text")->pack(-side=>'bottom', -fill=>'both',-expand=>1); open(FH,"$filename"); while(<FH>) {$open_curr->insert("end",$_);} close(FH); } sub see_list { my %temp_see_list; opendir(SPAM,$spam_dir); my @files=readdir(SPAM); close(SPAM); my @deleted=grep(/^deleted/,@files); my $new=$w->Toplevel; $new->title("List of Deleted Files"); foreach my $open (@deleted) { $temp_see_list{$open}=$new->Button(-text=> "$open", -command=>sub{&view("$spam_dir/$open")}, -fg=>'black', -bg=>'tan', -activebackground=>'blue', -activeforeground=>'red')->pack; } } sub view { ($file)=@_; my $newer=$w->Toplevel; $newer->title("$file Listing"); $open_this=$newer->Scrolled("Text")->pack(-side=>'bottom', -fill=>'both',-expand=>1); open(FH,"$file"); my @temp=<FH>; close(FH); foreach $line (@temp) {$open_this->insert("end",$line);} }
In reply to Re: creating tk buttons with for loop
by K_M_McMahon
in thread creating tk buttons with for loop
by K_M_McMahon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |