Add cron script for removing aged extracted comics
This commit is contained in:
parent
8a38d3ce9f
commit
f1d68e0ce6
2
cron/.htaccess
Normal file
2
cron/.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
order allow,deny
|
||||||
|
deny from all
|
9
cron/README.md
Normal file
9
cron/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
## Scripts intended for use by cron
|
||||||
|
|
||||||
|
Scripts in this folder are intended to be run by cron, likely as the user running the web server process.
|
||||||
|
|
||||||
|
* __clearextracts.php:__ Used to purge the folder used for extracting comics for viewing by clients. It should be run by the web service owner and takes a single parameter for the number of days to keep extracts before removing them.
|
||||||
|
- "su" to root: `sudo su -`
|
||||||
|
- Run crontab as web server owner: `sudo web -c "crontab -e"`
|
||||||
|
- Add crontab line with frequency and days/age parameter
|
||||||
|
- `15 3 * * * /usr/local/bin/php /var/www/htdocs/comics/cron/clearextracts.php 5 1>/dev/null 2>&1`
|
27
cron/clearextracts.php
Normal file
27
cron/clearextracts.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$projectRoot = dirname(dirname(__FILE__));
|
||||||
|
|
||||||
|
require "{$projectRoot}/header.php";
|
||||||
|
|
||||||
|
if ( $argc != 2 ) {
|
||||||
|
echo "Invalid number of days to keep\n";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$daysToKeep = intval($argv[1]);
|
||||||
|
|
||||||
|
$ed = $projectRoot . "/" . EXTRACTSDIR;
|
||||||
|
$now = time();
|
||||||
|
$maxAge = $now - (86400*$daysToKeep);
|
||||||
|
|
||||||
|
$it = new RecursiveDirectoryIterator($ed, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
|
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||||
|
$validExtensions = array("cbr","cbz");
|
||||||
|
foreach ( $files as $file ) {
|
||||||
|
if ( $file->isDir() && in_array($file->getExtension(), $validExtensions) ) {
|
||||||
|
if ( filemtime($file->getRealPath()) <= $maxAge ) {
|
||||||
|
echo "Found aged extracted comic: {$file->getFilename()}\n";
|
||||||
|
exec("rm -rf \"{$file->getRealPath()}\"", $output, $retval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user