Lex
Lex

Reputation: 396

Getting updated values for Filesys::DiskFree

So i'm working on a script to remove some old backups when the disk space available goes bellow a certain percentage.

    # get disk info
    $handle = Filesys::DiskFree->new();
    $handle->df();
    $available = $handle->avail("$dir");
    $used = $handle->used("$dir");
    $total = $handle->total("$dir");
    $used_p = ($used / $total) * 100.0;
    print "$used_p\n";
    print "$used\n";

    # find files to delete
    # --- special sauce code to find @files

    # delete files
    unlink @files;

    # get new disk info
    $handle = Filesys::DiskFree->new();
    $handle->df();
    $available = $handle->avail("$dir");
    $used = $handle->used("$dir");
    $used_p = ($used / $total) * 100.0;
    print "$used_p\n";
    print "$used\n";

My thinking was that the second time i used Filesys::DiskFree I would get the new df values which should reflect the files deleted. However, is not giving me the values i expect. Is not exactly the same, but the difference is not nearly as much as I expect. However the second time i run it I can see that the initial print reflects the files being deleted on the previous run. It is as if there was some sort of delay. As shown above, I tried calling new() again to see if that would clear stale data.

Upvotes: 0

Views: 67

Answers (1)

stevieb
stevieb

Reputation: 9296

It's possible that the system isn't releasing the disk space until the application terminates. Much like a long running application that generates large log files, deleting the file removes it, but the space isn't freed until the application is reloaded. Try an lsof | grep deleted... you may see your files still listed, and if so and they're gone after the app terminates, this is the issue.

Upvotes: 1

Related Questions