1Rex::Commands::Cron(3)User Contributed Perl DocumentationRex::Commands::Cron(3)
2
3
4

NAME

6       Rex::Commands::Cron - Simple Cron Management
7

DESCRIPTION

9       With this Module you can manage your cronjobs.
10

SYNOPSIS

12        use Rex::Commands::Cron;
13
14        cron add => "root", {
15               minute => '5',
16               hour  => '*',
17               day_of_month   => '*',
18               month => '*',
19               day_of_week => '*',
20               command => '/path/to/your/cronjob',
21             };
22
23        cron list => "root";
24
25        cron delete => "root", 3;
26

EXPORTED FUNCTIONS

28   cron_entry($name, %option)
29       Manage cron entries.
30
31        cron_entry "reload-httpd",
32          ensure       => "present",
33          command      => "/etc/init.d/httpd restart",
34          minute       => "1,5",
35          hour         => "11,23",
36          month        => "1,5",
37          day_of_week  => "1,3",
38          day_of_month => "1,3,5",
39          user         => "root",
40          on_change    => sub { say "cron added"; };
41
42        # remove an entry
43        cron_entry "reload-httpd",
44          ensure       => "absent",
45          command      => "/etc/init.d/httpd restart",
46          minute       => "1,5",
47          hour         => "11,23",
48          month        => "1,5",
49          day_of_week  => "1,3",
50          day_of_month => "1,3,5",
51          user         => "root",
52          on_change    => sub { say "cron removed."; };
53
54   cron($action => $user, ...)
55       With this function you can manage cronjobs.
56
57       List cronjobs.
58
59        use Rex::Commands::Cron;
60        use Data::Dumper;
61
62        task "listcron", "server1", sub {
63          my @crons = cron list => "root";
64          print Dumper(\@crons);
65        };
66
67       Add a cronjob.
68
69       This example will add a cronjob running on minute 1, 5, 19 and 40.
70       Every hour and every day.
71
72        use Rex::Commands::Cron;
73        use Data::Dumper;
74
75        task "addcron", "server1", sub {
76           cron add => "root", {
77             minute => "1,5,19,40",
78             command => '/path/to/your/cronjob',
79           };
80        };
81
82       This example will add a cronjob running on the 1st, 3rd and 5th day of
83       January and May, but only when it's a Monday or Wednesday. On those
84       days, the job will run when the hour is 11 or 23, and the minute is 1
85       or 5 (in other words at 11:01, 11:05, 23:01 and 23:05).
86
87        task "addcron", "server1", sub {
88           cron add => "root", {
89             minute => "1,5",
90             hour  => "11,23",
91             month  => "1,5",
92             day_of_week => "1,3",
93             day_of_month => "1,3,5",
94             command => '/path/to/your/cronjob',
95           };
96        };
97
98       Delete a cronjob.
99
100       This example will delete the 4th cronjob. Counting starts with zero
101       (0).
102
103        task "delcron", "server1", sub {
104           cron delete => "root", 3;
105        };
106
107       Managing Environment Variables inside cron.
108
109        task "mycron", "server1", sub {
110           cron env => user => add => {
111             MYVAR => "foo",
112           };
113
114           cron env => user => delete => $index;
115           cron env => user => delete => 1;
116
117           cron env => user => "list";
118        };
119
120
121
122perl v5.32.1                      2021-03-06            Rex::Commands::Cron(3)
Impressum