I am trying to run a Perl script (test.pl) once every minute without using crontab
. Since I will not have access to write cron jobs into /etc/cron.d/
, I am using the Perl module Schedule::Cron
.
I have included the code for test.pl in a script that is running continuously and given code like:
my $cron = new Schedule::Cron(sub {});
$cron->add_entry("* * * * *",\&test_function);
$cron->run(nofork=>1)
The issue is that the line
$cron->run(nofork=>1)
never returns back to the main script, and it is not executing any code that are given after that.
I need a solution for this to run cron in the background (using Schedule::Cron
) and then return back to the main script for executing the remaining script.
Change:
$cron->run(nofork=>1)
to:
$cron->run(detach=>1)
This returns immediately to the main script. From Schedule::Cron (detach):
If set to a true value the scheduler process is detached from the current process (UNIX only).