Rex::C...s::Cron(3pm)

πŸ’– Rex::Commands::Cron(3pm) β€” the group chat version πŸ’–

okay so bestie, welcome to Rex::C...s::Cron(3pm) (yes that's the truncated man-page name, iconic of it honestly), which lives in the User Contributed Perl Documentation corner of the internet. pull up a chair. πŸͺ‘


✨ NAME ✨

Rex::Commands::Cron β€” Simple Cron Management πŸŽ€

that's it. that's the whole vibe. your cronjobs, but managed, but make it Rex.


🌸 DESCRIPTION 🌸

With this Module you can manage your cronjobs. πŸ’…

that's the tea, fr fr. cronjobs = handled. no cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the sneak peek, the trailer, the little taste πŸ“:

use Rex::Commands::Cron;

cron add => "root", {
       minute => '5',
       hour  => '*',
       day_of_month   => '*',
       month => '*',
       day_of_week => '*',
       command => '/path/to/your/cronjob',
     };

cron list => "root";

cron delete => "root", 3;

see how clean that is?? adding, listing, deleting. three little moves. slay. ✨


πŸ‘‘ EXPORTED FUNCTIONS πŸ‘‘

🧚 cron_entry($name, %option)

Manage cron entries. that's the whole job description bestie.

here's what it looks like when you're adding one:

cron_entry "reload-httpd",
  ensure       => "present",
  command      => "/etc/init.d/httpd restart",
  minute       => "1,5",
  hour         => "11,23",
  month        => "1,5",
  day_of_week  => "1,3",
  day_of_month => "1,3,5",
  user         => "root",
  on_change    => sub { say "cron added"; };

and here's the same energy but for removing it:

# remove an entry
cron_entry "reload-httpd",
  ensure       => "absent",
  command      => "/etc/init.d/httpd restart",
  minute       => "1,5",
  hour         => "11,23",
  month        => "1,5",
  day_of_week  => "1,3",
  day_of_month => "1,3,5",
  user         => "root",
  on_change    => sub { say "cron removed."; };
ngl the ensure => "absent" one is giving reverse-card energy. same entry, same fields, just gone now. πŸ’€

πŸŽ€ cron($action => $user, ...)

With this function you can manage cronjobs. periodt.

Listing cronjobs πŸ’–

use Rex::Commands::Cron;
use Data::Dumper;

task "listcron", "server1", sub {
  my @crons = cron list => "root";
  print Dumper(\@crons);
};

you get them all back in an array and you dump them. iconic. πŸ“‹βœ¨

Adding a cronjob ✨

This example will add a cronjob running on minute 1, 5, 19 and 40. Every hour and every day.

use Rex::Commands::Cron;
use Data::Dumper;

task "addcron", "server1", sub {
   cron add => "root", {
     minute => "1,5,19,40",
     command => '/path/to/your/cronjob',
   };
};

look at that. every hour, every day, at minutes 1, 5, 19 and 40. she's punctual, she's dependable, she's a cronjob. 🫢

okay and now for the fancy one β€” this example will add a cronjob running on the 1st, 3rd and 5th day of January and May, but only when it's a Monday or Wednesday. On those days, the job will run when the hour is 11 or 23, and the minute is 1 or 5 (in other words at 11:01, 11:05, 23:01 and 23:05).

task "addcron", "server1", sub {
   cron add => "root", {
     minute => "1,5",
     hour  => "11,23",
     month  => "1,5",
     day_of_week => "1,3",
     day_of_month => "1,3,5",
     command => '/path/to/your/cronjob',
   };
};

the way that this one is specific... she knows exactly when she wants to run and honestly? respect. πŸ’… 11:01, 11:05, 23:01, 23:05 β€” four little moments, only in January and May, only Mon/Wed. picky queen. πŸ‘‘

Deleting a cronjob πŸ’€

This example will delete the 4th cronjob. Counting starts with zero (0).

task "delcron", "server1", sub {
   cron delete => "root", 3;
};
careful bestie: index 3 is the 4th one because counting starts with zero (0). zero-indexed brain required. πŸ™ˆ

Managing Environment Variables inside cron 🌈

yes you can carry env vars into cron land, watch:

task "mycron", "server1", sub {
   cron env => user => add => {
     MYVAR => "foo",
   };

   cron env => user => delete => $index;
   cron env => user => delete => 1;

   cron env => user => "list";
};

adding, deleting by index, deleting by literal 1, and listing. all of it. env var main character energy. ⭐


πŸ“ SEE ALSO πŸ“

nothing listed here in the original bestie, so… nothing to see. just you and your crons. πŸ¦‹


that's the whole page, and for the record, this one shipped with perl v5.40.1 and got written down on 2025-10-03, under the tiny truncated name Rex::C...s::Cron(3pm). bye bestie, go schedule something πŸ’œβœ¨

πŸ“¦ where this page comes from