crontab n'est pas modifié
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user