-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Neto
committed
Jan 9, 2025
1 parent
fea8953
commit a5c51d8
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
// Ensure the script is being run from the command line | ||
if (php_sapi_name() !== 'cli') { | ||
die("This script can only be run from the command line.\n"); | ||
} | ||
|
||
// Set the directory pattern to search for | ||
$baseDir = '/tmp/systemd-private-*/tmp'; | ||
|
||
// Find all matching directories | ||
$dirs = glob($baseDir, GLOB_ONLYDIR); | ||
|
||
// Check if there are any matching directories | ||
if (empty($dirs)) { | ||
echo "No matching directories found.\n"; | ||
exit(0); | ||
} | ||
|
||
$oneDayAgo = time() - (24 * 60 * 60); // Timestamp for 1 day ago | ||
|
||
foreach ($dirs as $dir) { | ||
echo "Processing directory: $dir\n"; | ||
|
||
// Get all files in the directory | ||
$files = glob("$dir/*"); | ||
foreach ($files as $file) { | ||
// Check if it's a file and if it's older than 1 day | ||
if (is_file($file) && filemtime($file) < $oneDayAgo) { | ||
echo "Deleting file: $file\n"; | ||
unlink($file); | ||
} | ||
} | ||
} | ||
|
||
echo "Cleanup complete.\n"; |