From f1d68e0ce6a684b826900664aacd4ccb9e8d24ba Mon Sep 17 00:00:00 2001 From: Junior Date: Tue, 22 Aug 2023 15:35:01 -0400 Subject: [PATCH] Add cron script for removing aged extracted comics --- cron/.htaccess | 2 ++ cron/README.md | 9 +++++++++ cron/clearextracts.php | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 cron/.htaccess create mode 100644 cron/README.md create mode 100644 cron/clearextracts.php diff --git a/cron/.htaccess b/cron/.htaccess new file mode 100644 index 0000000..281d5c3 --- /dev/null +++ b/cron/.htaccess @@ -0,0 +1,2 @@ +order allow,deny +deny from all diff --git a/cron/README.md b/cron/README.md new file mode 100644 index 0000000..6e4f292 --- /dev/null +++ b/cron/README.md @@ -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` diff --git a/cron/clearextracts.php b/cron/clearextracts.php new file mode 100644 index 0000000..25906c0 --- /dev/null +++ b/cron/clearextracts.php @@ -0,0 +1,27 @@ +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); + } + } +}