crontab n'est pas modifié
This commit is contained in:
@@ -100,12 +100,14 @@ function ensure_crontab_entries() {
|
|||||||
$updated = false;
|
$updated = false;
|
||||||
|
|
||||||
foreach ($required_jobs as $job) {
|
foreach ($required_jobs as $job) {
|
||||||
$parts = explode(' ', $job);
|
// Extraction intelligente du nom du script (ex: check_disk.php)
|
||||||
$script_path = $parts[5]; // Chemin du script
|
// On cherche simplement si le chemin vers /bin/nom_du_script est dans le cron
|
||||||
|
preg_match('/\/bin\/([a-z0-9_-]+\.(php|sh))/i', $job, $matches);
|
||||||
|
$script_name = $matches[0] ?? $job;
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
if (strpos($line, $script_path) !== false) {
|
if (strpos($line, $script_name) !== false) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -114,15 +116,20 @@ function ensure_crontab_entries() {
|
|||||||
if (!$found) {
|
if (!$found) {
|
||||||
$lines[] = $job;
|
$lines[] = $job;
|
||||||
$updated = true;
|
$updated = true;
|
||||||
echo "\e[32m[OK]\e[0m Ajout au cron : " . basename($script_path) . "\n";
|
echo "\e[32m[OK]\e[0m Ajout au cron : $script_name\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updated) {
|
if ($updated) {
|
||||||
|
// On s'assure qu'il n'y a pas de lignes vides inutiles et on joint avec un saut de ligne final
|
||||||
|
$content = implode("\n", array_filter($lines, 'trim')) . "\n";
|
||||||
$tmp_cron = tempnam(sys_get_temp_dir(), 'cron');
|
$tmp_cron = tempnam(sys_get_temp_dir(), 'cron');
|
||||||
file_put_contents($tmp_cron, implode("\n", $lines) . "\n");
|
file_put_contents($tmp_cron, $content);
|
||||||
exec("crontab " . escapeshellarg($tmp_cron));
|
exec("crontab " . escapeshellarg($tmp_cron));
|
||||||
unlink($tmp_cron);
|
unlink($tmp_cron);
|
||||||
|
echo "\e[32m[OK]\e[0m Crontab mis à jour avec succès.\n";
|
||||||
|
} else {
|
||||||
|
echo "[INFO] Crontab déjà à jour.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user