crontab - Deleting individual cron jobs using PHP -
i have php script sets cron job once data inserted sql database:
<? $output = shell_exec('crontab -l'); file_put_contents('/tmp/crontab.txt', $output.'* * * * * /usr/local/bin/php /home/dldl1330/public_html/new/mailchimp.php'.php_eol); echo exec('crontab /tmp/crontab.txt'); ?>
this cron job executes script syncs sql db mailchimp. in mailchimp php script deletes cron tab:
echo exec('crontab -r');
once happens loose jobs in cron tab (and removes email gets emailed after every cron job), how can make above line deletes /home/dldl1330/public_html/new/mailchimp.php
cron job?
i used above advise , came solution, not sure how efficient or correct is.... welcome comments.
note: //find string section in there debugging/learning purposes
<?php //get contents of cron tab $output = shell_exec('crontab -l'); echo "<pre>$output</pre>"; //find string $cronjob = ('* * * * * /usr/local/bin/php /home/dldl1330/public_html/new/mailchimp.php'); if (strstr($output, $cronjob)) { echo 'found'; } else { echo 'not found'; } //copy cron tab , remove string $newcron = str_replace($cronjob,"",$output); echo "<pre>$newcron</pre>"; file_put_contents('/tmp/crontab.txt', $newcron.php_eol); echo exec('crontab /tmp/crontab.txt'); ?>
Comments
Post a Comment