in reply to Crontab replacement in Perl
If you have a shell account, you should be able to run crontab -e to edit your user crontab.
Just for reference, here is a low level version to execute one thing at a specific time every day (untested, from memory):
... my $targettimetext = "13:14:15"; # Turn target time into seconds my @tttparts = split/\:/, $targettimetext; my $targettime = ($tttparts[0] * 3600) + ($tttparts[1] * 60) + $tttpar +ts[2]; ... while(1) { # Turn the current time into seconds my ($sec,$min, $hour, $mday,$mon, $year, $wday,$yday, $isdst) = lo +caltime time; my $nowtime = ($hour * 3600) + ($minute * 60) + $sec; # Not yet time to do things? Sleep until it is if($nowtime < $targettime) { sleep($targettime - $nowtime); } # YOUR STUFF HERE # Recalculate the current time after doing stuff ($sec,$min, $hour, $mday,$mon, $year, $wday,$yday, $isdst) = local +time time; $nowtime = ($hour * 3600) + ($minute * 60) + $sec; # Sleep for the rest of the day sleep(86400 - $nowtime); }
Edit: Please be aware, the simplistic approach above doesn't account for all the time calculation weirdness like daylight savings time changes, leap seconds and skipped days. For that, i refer you to this excellent Tom Scott video.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Crontab replacement in Perl
by soonix (Chancellor) on Feb 07, 2022 at 20:33 UTC | |
by cavac (Prior) on Feb 08, 2022 at 16:48 UTC | |
by soonix (Chancellor) on Feb 09, 2022 at 08:33 UTC | |
by cavac (Prior) on Feb 09, 2022 at 20:54 UTC |