Actually you have to read the current state from harddisk back into your variables at the very beginning of the program. I'm just setting my variable to 1 out of laziness.#!/usr/bin/perl # 529755.pl use strict; use diagnostics; my $importantdatatomangle = 1; sub checkfornew { my $newversionfilename = '529755.pl.newversion'; if ( -e $newversionfilename # does the new file exist? and (time - (stat $newversionfilename)[9] > 2) # is it older than 2 sec, i.e. has it been completely # transferred to this here box? ) { # save the current state of the program out to harddisk # i.e. $importantdatatomangle # ... warn "found a new version, running updater"; exec 'perl updater.pl' or die "could not exec updater: $!"; # run the updater # see perldoc -f exec why I included error checking }; }; # main program starts below here while (1) { # loop for "many hours", actually forever :p { # do important work $importantdatatomangle = -$importantdatatomangle; warn "data is now $importantdatatomangle"; sleep 5; warn "zzzzz"; }; checkfornew; # periodically check for newer version };
Next time on perlmonks, show what you have programmed so far, or else you get slapped with a wet octopus.#!/usr/bin/perl # updater.pl use strict; use diagnostics; use File::Copy; # improve this shoddy programming, # remember to actually check the return values of move for errors move '529755.pl', '529755.pl~'; # create backup move '529755.pl.newversion', '529755.pl'; # deploy new version warn "deployed new version, going to run it now"; exec 'perl 529755.pl' or die "could not exec new version: $!";
In reply to Re: Restart Long Running Perl Script
by Anonymous Monk
in thread Restart Long Running Perl Script
by avo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |