Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use File::stat; my(%files, $create_date, $file, $current_date, $code); my($hometime, $log, $worktime, $location, $url, $set_time); my($home_image, $work_image, $code_color); # ------------------------------------------------ # Script created by David Wakeman, 2001. # # I have this setup to use the /var/www/images dir # for my cam images, and the /var/www dir to use # for the text files in my server-side includes. # # Test to see if the most recent image of your # specified images (%files hash) is newer than # your specified amount of time ($set_time). If # it is, that is the current image displayed on # your cam, if not, the camera is offline. # # If you don't have SSI enabled in your Apache # configs, go to apache.org and read their Docs # to learn how it works, and how to enable it. # ------------------------------------------------ # ----------------------------------------------- # START OF CONFIG AREA # ----------------------------------------------- # $code is used for the top part of my cam where # you see: $cam = ( work | home | offline ); # My index page has this for that line: # $cam = ( <!--#include virtual="code.txt"--> ); # It basically highlights the current location # in whatever you put for $code_color below. $code = "/var/www/code.txt"; # Put the highlight color of your choice here. # Default = orange. $code_color = "#F07800"; # $url is used for the java applet running the # cam refresh on my page. The java applet code's # param name="url" value="" uses SSI as above to # include the correct URL of The Moment (tm). $url = "/var/www/url.txt"; # $cam is used for the blurb under my cam that # says ".. camera image is from $location ..". # Again, this uses SSI from the index page. $file = "/var/www/cam.txt"; # $log = logfile - duh. $log = "/home/iago/camlog"; # Here is the location of your work and image # files. $home_image = "/var/www/images/home.jpg"; $work_image = "/var/www/images/work.jpg"; # Here is the amount of time you want to test # your most current file against. Value is # in seconds. $set_time = 600; # ----------------------------------------------- # END OF CONFIG AREA # ----------------------------------------------- $current_date = time; # epoch time $create_date = 0; $worktime = 0; $hometime = 0; $location = ""; %files = ( home => "$home_image", work => "$work_image", ); $hometime = stat($files{home})->ctime; # This checks each file +for current $worktime = stat($files{work})->ctime; # epoch time. # This figures out if the newest file is newer than # our $set_time, if not - cam is off. # -------------------------------------------------- if ($worktime > $hometime && $current_date - $worktime < $set_time) + { $location = "work"; # dood, i'm at work. blah adjust_cam($location); } elsif ($hometime > $worktime && $current_date - $hometime < $set_time) { $location = "home"; # dood! i'm at home! weee adjust_cam($location); } else { $location = "offline"; # dood, i'm hiding... adjust_cam($location); } # This sub changes all our SSI txt files needed # for the cam applet. # ----------------------------------------------- sub adjust_cam { open(FILE, "+>$file") || die "can't open file: ($!)\n"; if ($location eq "home" || $location eq "work") { print FILE ".. current image is from <b>$location</b> .."; } else { print FILE ".. camera is currently offline .."; } open(URL, "+>$url") || die "can't open file: ($!)\n"; print URL "http://www.gibfest.org/images/$location.jpg"; open(CODE, "+>$code") || die "can't open file: ($!)\n"; if ($location eq "home") { print CODE "work | <font color=\"$code_color\">$location</font +> | offline"; } elsif ($location eq "work") { print CODE "<font color=\"$code_color\">$location</font> | hom +e | offline"; } else { print CODE "work | home | <font color=\"$code_color\">$locatio +n</font>"; } } close(FILE); close(URL);

In reply to Cam Check by djw

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (6)
    As of 2014-12-22 05:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (110 votes), past polls