Skip to content

Commit

Permalink
Rewind file after write
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Sep 10, 2019
1 parent 0275aa7 commit b57256a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions perfdata-purge
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down

0 comments on commit b57256a

Please sign in to comment.