Skip to content
Permalink
Browse files

Rewind file after write

  • Loading branch information...
NEMS Linux
NEMS Linux committed Sep 10, 2019
1 parent 0275aa7 commit b57256a7c9e292d51baadfa13981cebd132c015e
Showing with 4 additions and 2 deletions.
  1. +4 −2 perfdata-purge
@@ -10,12 +10,14 @@
while (!$perfdata->eof()) {
$line = $perfdata->fgets();
$tmp = explode('||',$line);
$timestamp = $tmp[0];
$timestamp = intval($tmp[0]);
if ($timestamp < strtotime($cutoff . ' days ago')) {
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");
$result = shell_exec("/bin/sed -i '/^$timestamp||/d' $file");
// We changed the file, rewind!
$perfdata->rewind();
$counter++;
}
}

0 comments on commit b57256a

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