/MacOS-Periodic-Rotate-Apache-Log

A script for rotating logs, using datestamps, via MacOS' Periodic Maintenance system

Primary LanguageShellThe UnlicenseUnlicense

#MacOS Periodic Rotation of Apache Logs ##Usage A shell script used by Mac OS's periodic (daily, weekly, monthly) maintenance system to rotate all logs in a given directory.

I created this to manage the Apache and PHP logs generated by my local dev hosting setup. (Setup as per https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew .)

##Steps

  1. Open "110.rotate-logs" in your favorite code editor.
  2. Edit the path to point to the directory containing the logs you want rotated.
  3. Edit the wildcard to match the log files. (e.g.: *.log, *_log…)
  4. Optional: edit the datestamp format.
  5. Save file and close.
  6. Copy "110.rotate-logs" to /private/etc/periodic/monthly (or weekly, or daily)
  7. Done.

##Notes

  1. The 3 digit prefix on the filename seems only to indicate the execution order of scripts in the folder.
  2. Multiple instances of this script can be run, one for each directory of logs you want rotated. Simply run through the Steps above.
  3. Rename the file as needed. "rotate-apachelogs", "rotate-lincolnlogs", whatever.
  4. The new log files can be created with the same user and perms as the user running the script, and CHMODed as needed. Uncomment the "touch,chmod & chown" at line 30 and edit as you need.

Enjoy.

This script is offered as-is, with no support promised or offered.


##UnLicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/