Rex::Commands::Cron - Simple Cron Management
获取主机的crontab任务:
task "listcron", "192.168.137.3", sub {
my @crons = cron list => "root";
my $r=@crons;
#print Dumper($r);
foreach (@{$r}){
say $_->{'line'};
};
};
[root@node01 Rex]# rex listcron
[2017-05-06 22:15:09] INFO - Running task listcron on 192.168.137.3
*/10 * * * 5 sh /root/a1.sh
09 * * * 5 sh /root/t1.sh
08 * * * 3 sh /root/s1.sh
[2017-05-06 22:15:20] INFO - All tasks successful on all hosts
添加任务。
这个示例会添加一个在每天每小时的第 1,5,19,和40分钟运行的任务。
task "addcron", "192.168.137.3", sub {
cron add => "root", {
minute => "1,5,19,40",
command => 'sh /root/aa/t1.sh',
};
};
[root@node01 Rex]# rex addcron
node2:/root#crontab -l
*/10 * * * 5 sh /root/a1.sh
09 * * * 5 sh /root/t1.sh
08 * * * 3 sh /root/s1.sh
1,5,19,40 * * * * sh /root/aa/t1.sh