Here is a prototype of the file update script. The idea is that the server does CRC xml of all files in a folder, then the client on its side compares the CRC with the local folder that must be updated. Upon difference between the two the client requires the file from server Mime encoded in XML, then updates the local copy.
use strict; use File::Find; use Digest::MD5; use MIME::Base64; use XML::Twig; my $twig= XML::Twig->new(); # XML Parser #lets get all folderz my %digest; my $cdir = "./"; my $distrodir = "/socket/.DIST/"; my $current_updates_xml; find( { wanted=>sub{ if ($_ !~ /temp|\.log/) { my $filename = $_; if (-f $File::Find::name) { open(FILE, "<$File::Find::nam +e") or die "Can't open '$File::Find::name': $!"; binmode(FILE); $digest{$cdir}{$filename} = Di +gest::MD5->new->addfile(*FILE)->hexdigest; close FILE; } elsif (-d $File::Find::name) { $cdir=$File::Find::name; $cdir =~ s/^$distrodir//; $digest{$cdir} = () unless ($ +cdir."/" eq $distrodir); } } }, chdir=>1 },$distrodir); #generate XML $current_updates_xml = qq~<?xml version="1.0" standalone="yes"?> <data +>\n~; foreach my $folder (sort {$a cmp $b} keys %digest) { $current_updates_xml .= "<folder name=\"$folder\">\n"; foreach my $file (keys %{$digest{$folder}}) { $current_updates_xml .= "<file name=\"$file\" crc=\"$d +igest{$folder}{$file}\" />\n" } $current_updates_xml .= "</folder>"; } $current_updates_xml .= "</data>\n"; #print $current_updates_xml; # client side $twig->parse($current_updates_xml); my $root = $twig->root; my %redigest; foreach my $folder ($root->children('folder')) { $redigest{$folder->att('name')} = (); foreach my $file ($folder->children('file')) { $redigest{$folder->att('name')}{$file->att('name')} = $file->a +tt('crc'); } } #TEMPORARY SECTION my $destfolder = "/socket/REDIST/"; my %tofetch; #create directory structure foreach my $folder (sort {$a cmp $b} keys %redigest) { mkdir $destfolder.$folder unless (-d $destfolder.$folder); # print "$folder\n"; foreach my $file (keys %{$redigest{$folder}}) { #compare files #print "\t $destfolder$folder/$file (CRC: $redigest{$folder}{$ +file}\n"; if (-f "$destfolder$folder/$file") { open(FILE, "$destfolder$folder +/$file") or die "Can't open $destfolder$folder/$file: $!"; binmode(FILE); $tofetch{$folder}{$file} = 1 +if (Digest::MD5->new->addfile(*FILE)->hexdigest ne $redigest{$folder} +{$file}); close FILE; } else { $tofetch{$folder}{$file} = 1 } } } #debug foreach my $folder (keys %tofetch) { #print join(", ", keys %{$tofetch{$folder}}); #print "\n"; foreach my $file (keys %{$tofetch{$folder}}) { my $requestxml; # = qq~<?xml version="1.0" standalone="yes"?> <data>\n~; $requestxml .= "<data command=\"getbinfile\" folder=\"$folder\ +" file=\"$file\" />\n"; my $filexml = server_return($requestxml); $twig->parse($filexml); my $root = $twig->root; if ($root->att('status') == 1) { my $filebindata = $root->att('binfile'); $filebindata = MIME::Base64::decode($filebindata); open(OUT, "> $destfolder$folder/$file") or die "can't open + $_[1]: $!"; syswrite OUT, $filebindata; close OUT; } } } sub server_return { my $distrodir = "/socket/.DIST/"; my $ixml = shift; $twig->parse($ixml); my $root = $twig->root; my $file = $root->att('file'); my $folder = $root->att('folder'); print $file; my $encoded; my $status; if (-f "$distrodir$folder/$file") { $encoded = MIME::Base64::encode(slurpfile("$di +strodir$folder/$file")); $status = 1; } else { $status = 0; } my $oxml = "<?xml version=\"1.0\" standalone=\ +"yes\"?> <data status=\"$status\" binfile=\"$encoded\"/>\n"; return $oxml; } sub slurpfile { open(IN, "< $_[0]") or die "can't open $_[0]: $!"; binmode (IN); seek(IN, 0, 0); sysread (IN, my $slurp, -s IN); close(IN); return $slurp; }

In reply to Re^2: Restart Long Running Perl Script by avo
in thread Restart Long Running Perl Script by avo

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.