#!/usr/bin/perl # always_be_running.pl use strict; use warnings; use File::Temp (); # creates a temporary file in /tmp which is removed when the script exits my $fh = new File::Temp(); my $fname = $fh->filename; # now open another file and write the name of the temp file to it my $checkme = "/home/mojodaddy/checkme.txt"; open CHECKME, "+>$checkme" || die "Can't open checkme file: $!\n"; print CHECKME $fname; close CHECKME; print "Script says: 'Hey, I just started running!'\n"; sleep 60; # or whatever print "Script says: 'Boy, I'm bushed! I'm gonna go lie down.'\n"; #### #!/usr/bin/perl # check_if_its_running.pl use strict; use warnings; my $line; my $checkme = "/home/mojodaddy/checkme.txt"; start_it(); while (1) { open CHECKME, "<$checkme" || die "Couldn't open checkme file: $!\n"; while (){ # get the line with the name of the tempfile $line = $_; } close CHECKME; if (-e $line){ # see if the file exists print "(Checker says: 'Woo-hoo! Script is still running!')\n"; sleep 10; } else{ print "(Checker says: 'Doh! Script stopped running! I'd better restart it.')\n"; start_it(); } } sub start_it { system("perl always_be_running.pl"); }