I coach youth basketball, and need to check their schedule web page for available time slots for practice dates and snow cancellations etc, if I'm even the slightest bit late we wind up with the worst time slots available

I currently use a perl script to check their web page for text I define (inside) every hour via cron, example I use 12/20/08, because whenever they update their page includes the new date, so that seems to work for me.

if the date I define is not found inside the page it sends me a text to phone message, Problem I have is, it never stops emailing me until I get online and edit the script with the new date to stop that.

is there some kind of Perl code I can add to this script to linit the amount of alert emails being sent, to no more then 3 times etc? till I can get online and enter the new date inside the script

Since the perl program is being run by a cron job you could write the number of times the perl program runs to a file and check the number in the file when the script starts. If the number is 3 just exit the program. But then you have to reset the number in the file back to 0 before restarting the next the next session. -------------------------------------------------

Since the perl program is being run by a cron job you could write the number of times the perl program runs to a file and check the number in the file when the script starts. If the number is 3 just exit the program. But then you have to reset the number in the file back to 0 before restarting the next the next session.

Thanks for replying back so quickly

If someone can please move this over to the beginner thread for me, I obviously posted this in the wrong section,

If possible can you give an example I can use, as it would be included in my above code I pasted, if not thanks anyway

# Check if the requested webpage is there if ($res->is_success) { # Request successful $webpage = $res->content; # Store the page in the string $webpage }

@webpage = split(/\n/,$webpage);

foreach $line (@webpage) {

# Below is the text you want to look for (I use the date) # Example looking for 12/20/08 if ($line =~ /12\/20\/08/) { $found = "true"; # Ok, we found a webpage with the above text in the HTML-code. # So the webpage we are watching has not changed } }

Yes, File::CounterFile would need to be installed since it's not a core module, but that is a trivial task.

One improvement to my code, besides the already mentioned error handling, would be to put the $date assignment prior to retrieving the web page. Why? Because if the date wasn't passed, there would be no need to retrieve the web page. Part of the error handling on the $date assignment would be to send an email if it was undefined or if it wasn't in a valid format.

# Check if the requested webpage is there if ($res->is_success) { # Request successful $webpage = $res->content; # Store the page in the string $webpage }

@webpage = split(/\n/,$webpage);

foreach $line (@webpage) {

# Below is the text you want to look for (I use the date) # Example looking for 12/20/08 if ($line =~ /12\/20\/08/) { $found = "true"; # Ok, we found a webpage with the above text in the HTML-code. # So the webpage we are watching has not changed } }

I don't know, I have been trying to learn a little perl - php and thought I was getting somewhere but obviously not I guess I cant even tell you the opposite of "ne" I know you mentioned I am 2 characters away but it might as well be a 1000

# Below is the text you want to look for (I use the date) # Example looking for 12/20/08 if ($line =~ /12\/20\/08/) { $found = 1;#true # Ok, we found a webpage with the above text in the HTML-code. # So the webpage we are watching has not changed } }

If you're going to use a boolean flag, there is no need to initialize it to 0. An uninitialized var holds a value of undef and in boolean context that equates to false.

Personally, I would not use the flag. It would be better to correct the logic flow.

In its current form, the key purpose of this script is to send an email if the following 2 conditions are met; 1) the counter is less than 3, and 2) the specified date is in the web page. If the counter equals 3, then there is no need to check for the date so therefore, there is no reason to download the web page.

Checking the counter should be at the beginning of the script and the downloading of the web page should only be done if the counter is less than 3.

When checking/incrementing the counter, instead of opening the file twice, it would be more efficient to only open it once and use seek and truncate when updating. However, personally I'd use the File::CounterFile module which does this for you and includes file locking.

Since you're not setting a specific user agent, you could simply the retrieval of the web page by using LWP::Simple.

Here's an updated version and since there's no indication that this is run in a cgi environment, I left out the loading of the CGI::Carp module.

that makes a lot of sense about not wanting to download the page twice. I don't know how you and Kevin do this stuff so easy. after my brief experience with scripts, I have the utmost respect for programmers

Some times to test and make sure of things, I call it from the browser, I also noticed when you move up the alert count check code to the top, it writes (counts) every time the script runs instead of the times it sends the email.

That can come in handy for lets say checking a page for a set period of time depending on when and how many times a day you call it etc.

When I first posted I needed to check for a particular string on the page I was watching for example: 2/10/2009 and when that that page was updated the string would be changed and I would get a email "IF NOT FOUND" SEND EMAIL

The problem was that string would get changed whenever minor changes were being done, thus eating up my alert count

The latest script now looks for a string and "IF FOUND WILL" THEN SEND EMAIL

this is perfect and pretty much fool proof now, example if the page's server is down or minor changes are updated I do not get emailed

I look for a string like a future date 3/14/2009 and only when found will I get emailed about the update meaning new dates are available to me.

Although this might at a quick glance look like we went through this before, but this new opposite function is like night and day.

I am using the orig version with eq instead of ne and it works perfectly, Thanks to both of you, KevinR's log check code was perfect for limiting alets.