Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found