#!/usr/bin/perl use File::Copy; use strict; my $today_directory = "/home/www/bolling-cam/today/"; my $file_name; my $latest_image; my $source_path; my $current_image = "/home/www/bolling-cam/today/current.jpg"; my $timestamp = 0; my $latest_timestamp = 0; my $year; my $monthday; my $time; my $junk; # Find the most recent file in the today directory opendir(IMAGES, $today_directory) or die "Can't open $today_directory: $!"; while (defined ($file_name = readdir IMAGES) ) { next if $file_name =~ /^\.\.?$/; # skip . and .. next if $file_name eq "current.jpg"; ($junk, $year, $monthday, $time, $junk) = split("_", $file_name, 5); $timestamp = ($monthday * 1000000) + $time; if ($timestamp > $latest_timestamp) { $latest_image = $file_name; $latest_timestamp = $timestamp; } } # Sleep for 5 seconds to be certain the camera is done writing the file sleep(5); $source_path = $today_directory . $latest_image; copy($source_path, $current_image); closedir(IMAGES); exit;