From 61ebf5a92f4cefafdec6add5f2a0ba4b518a132d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Wed, 18 Mar 2026 08:32:49 +0100 Subject: [PATCH] =?UTF-8?q?crontab=20n'est=20pas=20modifi=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitoring/bin/monitoring-update.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/servers/linux/monitoring/bin/monitoring-update.php b/servers/linux/monitoring/bin/monitoring-update.php index e42970b..28ad5c4 100755 --- a/servers/linux/monitoring/bin/monitoring-update.php +++ b/servers/linux/monitoring/bin/monitoring-update.php @@ -100,12 +100,14 @@ function ensure_crontab_entries() { $updated = false; foreach ($required_jobs as $job) { - $parts = explode(' ', $job); - $script_path = $parts[5]; // Chemin du script - + // Extraction intelligente du nom du script (ex: check_disk.php) + // 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; foreach ($lines as $line) { - if (strpos($line, $script_path) !== false) { + if (strpos($line, $script_name) !== false) { $found = true; break; } @@ -114,15 +116,20 @@ function ensure_crontab_entries() { if (!$found) { $lines[] = $job; $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) { + // 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'); - file_put_contents($tmp_cron, implode("\n", $lines) . "\n"); + file_put_contents($tmp_cron, $content); exec("crontab " . escapeshellarg($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"; } }