#!/usr/bin/perl
use strict; use warnings;
`(crontab -l; echo "00 * * * * /home/slynux/download.sh") | crontab -`;
另一种(更好的)方法:
#!/usr/bin/perl
use strict; use warnings;
open my $fh, "| crontab -" || die "can't open crontab: $!";
my $cron = qx(crontab -l);
print $fh "$cron\n0 * * * * /home/slynux/download.sh\n";
close $fh;
要删除crontab行与/home/slynux/download.sh :
#!/usr/bin/perl
use strict; use warnings;
open my $fh, "| crontab -" || die "can't open crontab: $!";
my $cron = qx(crontab -l);
$cron =~ s!.*/home/slynux/download\.sh.*!!g;
print $fh $cron;
close $fh;