How about storing the date & time you have sent and email in a file then deleting the file when you detect problem has cleared? This way you could also add logic to send periodic alerts based on the time
John On Mon, Dec 10, 2012 at 3:39 PM, Alvin Ramos <w...@theflux.net> wrote: > I have a perl script that is running every 5 minutes to see if the mysql > server has a locked query, once it does, it sends me an email with > thread_connected and the query. I was curious, how could I write into the > script to send me the information one time instead of every 5 minutes after > it does find a lock? Below is a part where it looks for the threads, then > send email: > > # Thread connections > my $username = $np->opts->user; > my $password = $np->opts->password; > my $hostname = $np->opts->hostname; > my $contact = $np->opts->contactemail; > my $sendernot = $np->opts->senderemail; > my $locked = $query_hr->{Info}; > my $cmdline = "/usr/bin/mysql -h $hostname -P 3306 -u $username > -p$password"; > my $query_output = `/bin/echo "SHOW GLOBAL STATUS LIKE > 'Threads_connected';" \| $cmdline 2>/dev/null \| /bin/grep > "Threads_connected"`; > unless ($query_output =~ /^Threads_connected\s+(\d+)\s+$/) { > print "Unknown: Unable to read output from MySQL\n"; > } > # Send Email > my $msg = MIME::Lite->new( > From => $sendernot, > To => $contact, > Subject => 'MySQL MyISAM lock, additional information', > Encoding => 'base64', > Data => qq{ > Number of $query_output > Query causing lock: $locked > } > ); > $msg->send;