I have a question that involves POE. I trying to write a script that grabs a picture from a web cam every 30 second and every 30 minutes copies it to create an archive of pictures. To further complete things, I have two servers that this script needs to run on but the script only runs on one server depending on the status it reads from another server. The problem I am having is the subroutine that run every 30 minutes (move_pic) never runs. I will include the code that I have so far, but if any one can suggest a better way I would be happy to hear it.



Times shortened for testing...

#!/usr/bin/perl use strict; use warnings; use POE; use LWP::Simple; use File::Copy; use Net::SMTP; use POSIX qw(strftime); $|++; my $smtp = Net::SMTP->new('localhost'); my $host = qx { hostname --short }; my $lb; if ($host eq 'www0') { $lb = '10.0.0.1'; } else { $lb = '10.0.1.1'; } POE::Session->create( inline_states => { _start => \&start, check => \&check, get_pic => \&get_pic, move_pic => \&move_pic, mail => \&mail, _stop => \&stop, }, ); $poe_kernel->run; exit 0; sub start { my $kernel = $_[KERNEL]; $kernel->yield('check'); } sub check { my $kernel = $_[KERNEL]; my $servermon = qx { nc -w 2 $lb 5000}; if ($servermon eq $host) {; print "Check\n"; $kernel->delay(move_pic => 30); $kernel->delay(get_pic => 10); } else { $kernel->delay(check => 120); } } sub get_pic { my ($kernel, $heap) = @_[KERNEL, HEAP]; print "get_pic\n"; my $image_link = 'http://webcam/hugesize.jpg'; my $temp_filename = '30sec.jpg'; my $filename = 'current.jpg'; unless (mirror($image_link,$temp_filename)) { print "Sending mail\n"; $kernel->yield('mail'); } move($temp_filename,$filename); $kernel->yield('check'); } sub move_pic { my ($kernel, $heap) = @_[KERNEL, HEAP]; print "move_pic\n"; my $old_filename = 'current.jpg'; my $new_filename = time.'.jpg'; if (-f $old_filename) { copy($old_filename,$new_filename); } $kernel->yield('check'); } sub mail { my ($kernel, $heap) = @_[KERNEL, HEAP]; my $failTime = strftime "%H:%M:%S", localtime; my $todayDate = strftime "%m/%d/%y", localtime; $smtp->mail('wwwlb\@localhost'); $smtp->to('me\@locahost'); $smtp->data(); $smtp->datasend("To: me\@localhost\n"); $smtp->datasend("From: www0\@localhost\n"); $smtp->datasend("Subject: WebCam Died..."); $smtp->datasend("\n\n"); $smtp->datasend("Webcam failed will retry in one minute."); $smtp->datasend("\n\nDate: ".$todayDate."\nTime: ".$failTime." +\n\n"); $smtp->dataend(); $smtp->quit; $kernel->yield(get_pic => 60); } sub stop { print "That's All\n"; }
Thanks,
rlb3

In reply to POE me (Web Cam scripting Trouble) by rlb3

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.