Created
March 18, 2014 06:32
-
-
Save vdudouyt/9614633 to your computer and use it in GitHub Desktop.
Programmatically add a cronjob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub add_cronjob { | |
my ($spec) = @_; | |
local *getCmd = sub { | |
my @chunks = split(/\s+/, $_[0], 6); | |
return $chunks[5]; | |
}; | |
my $crontext_old = `crontab -l`; | |
my $existing = grep { getCmd($spec) eq getCmd($_) } split(/\n/, $crontext_old); | |
return if $existing; | |
open(CRONTAB, "| crontab -"); | |
print CRONTAB $crontext_old; | |
print CRONTAB "$spec\n"; | |
close(CRONTAB); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment