Using PHP to manage (add, remove) cronjobs! « home
posted on 12:49 - 06 July 2009 | posted by Lev
I've wondered about how this is best accomplished for a while, since "crontab -e" isn't actually a file you could just write to using traditional methods.
I searched around a while and found a whole lot of unhelpful responses by folks who, once again, never seem to understand the people asking a pretty simple question.
Fortunately, I eventually ran into a suggestion, which seemed to understand the idea here, unlikes countless others, and provided a simply idea for accomplishing just that.
See, when you run:
BASH CODE
It outputs the existing cronjob file. Piping that data into a file, like so:
BASH CODE
... will allow you to have a current working state of how cron is before you do anything.
And the other command that makes it all come together is:
BASH CODE
This reloads the cronjobs by wiping out whatever is in the crontab file and replacing it with whatever is in croncontents.txt.
Granted you still need to do some work using something like, exec, and you still need to work with the data yourself in PHP, these commands show that it is clearly possible to manipulate cronjobs using PHP!
SOURCE: http://www.webdeveloper.com/forum/showthread.php?t=128601
I searched around a while and found a whole lot of unhelpful responses by folks who, once again, never seem to understand the people asking a pretty simple question.
Fortunately, I eventually ran into a suggestion, which seemed to understand the idea here, unlikes countless others, and provided a simply idea for accomplishing just that.
See, when you run:
BASH CODE
crontab -l
It outputs the existing cronjob file. Piping that data into a file, like so:
BASH CODE
crontab -l > croncontents.txt
... will allow you to have a current working state of how cron is before you do anything.
And the other command that makes it all come together is:
BASH CODE
crontab croncontents.txt
This reloads the cronjobs by wiping out whatever is in the crontab file and replacing it with whatever is in croncontents.txt.
Granted you still need to do some work using something like, exec, and you still need to work with the data yourself in PHP, these commands show that it is clearly possible to manipulate cronjobs using PHP!
SOURCE: http://www.webdeveloper.com/forum/showthread.php?t=128601






