Skip to content
Permalink
Browse files

Purge lines in realtime, not at end

  • Loading branch information...
NEMS Linux
NEMS Linux committed Sep 10, 2019
1 parent 848d84b commit 0275aa7303edc37014300c33d70cbe689178c929
Showing with 8 additions and 8 deletions.
  1. +8 −8 perfdata-purge
@@ -6,24 +6,24 @@
$datachanged = 0;
$perfdata = new SplFileObject($file);
$removelines = array();
$counter = 0;
while (!$perfdata->eof()) {
$line = $perfdata->fgets();
$tmp = explode('||',$line);
$timestamp = $tmp[0];
if ($timestamp < strtotime($cutoff . ' days ago')) {
if (strlen($timestamp) > 0 && $timestamp > 0) $removelines[] = $timestamp;
if (strlen($timestamp) > 0 && $timestamp > 0) {
// Found some timestamps that are older than $cutoff.
// Delete those lines from $file using sed.
$result = shell_exec("sed -i '/^$timestamp||/d' $file");
$counter++;
}
}
}
$perfdata = null;
if (count($removelines) > 0) {
foreach ($removelines as $timestamp) {
// Found some timestamps that are older than $cutoff.
// Delete those lines from $file using sed.
$result = shell_exec("sed -i '/^$timestamp||/d' $file");
}
if ($counter > 0) {
echo 'Purged all perfdata that is older than ' . $cutoff . ' days.';
} else {
echo 'There was no perfdata older than ' . $cutoff . ' days. Nothing purged.';

0 comments on commit 0275aa7

Please sign in to comment.
You can’t perform that action at this time.