#!/usr/local/bin/perl use Getopt::Std; our ($opt_r); getopts('r:'); my $recover = uc $opt_r; $recover and goto ($recover); my $rec_file_name = 'start.rec'; FIRST: first(); SECOND: second(); THIRD: third(); CleanUp(); # do the first task sub first { # some other stuff may happen here, # so we'll go ahead and write the recovery info write_recovery_file('first'); print STDERR "This is first\n"; sleep(1); # die "died in first"; } sub second { write_recovery_file('second'); print STDERR "This is second\n"; sleep(1); # die "died in second"; } sub third { write_recovery_file('third'); print STDERR "This is third\n"; sleep(1); # die "died in third"; } sub CleanUp { `rm start.rec`; print "Recovery file deleted\n" unless ($?); } sub write_recovery_file { my $str = shift; open RECOVER, ">$rec_file_name"; print RECOVER "$0 -r$str\n"; close RECOVER; } #### #!/usr/local/bin/perl # This tests the recovery system $recovery_file = check_for_recovery_file(); # execute the script at either the recovery step or the beginning $recovery_file ? recover($recovery_file) : recover(); sub recover { my $file_name = shift; my $cmd_line = 'recover.pl'; if ($file_name) { open INFILE, "$file_name"; # assumes the recovery file contains # no more than one line of text chomp($cmd_line = ); print STDERR "Resuming failed process: '$cmd_line'"; } `$cmd_line`; die "Could not execute $file_name: $!" if ($?); print STDERR "'$cmd_line' successful\n"; } sub check_for_recovery_file { # won't hard-code this in real life $_ = 'start.rec'; (-s) ? return $_ : return 0 }