DATE=\`date "+%Y-%m-%d"\` DIR=\$* TOOOLD=31 #files older than this number of days are deleted. COMPOLD=8 #files older than this number of days are compressed. CHKLIST="find bzip2 rm" echo "logrotate: started." if [ \$# -gt 0 ]; then for a in "\$@"; do if [ -d \$a ]; then echo -e "\nDirectory exists : \$a" else echo -e "\nERROR: Directory does not exist : \$a" echo "Invalid directory, ending."; echo "logrotate: ERROR: Directory does not exist. Exiting." exit 1 fi done else echo -e "\nERROR: Must supply at least one valid Directory.\nUSAGE: /path/to/logrotate.sh /path/to/logs/ /any/valid/directories/ /as/many/as/you/wish/"; echo "logrotate: ERROR: No Directory supplied. Exiting." exit 1 fi # function to check necessary commands in \$PATH checkcmds() { for i in \$@ do command -v \$i > /dev/null && continue || echo -e "\nERROR:\n Command \$i not found in \\\$PATH: \n\$PATH.\n"; echo "logrotate: ERROR: Command \$i not found in \\\$PATH: \$PATH. Exiting."; exit 1; done echo -e "\nCommands all found : \$@ \n" } # check necessary commands (\$CHKLIST) via function checkcmds \$CHKLIST echo "logrotate: Deleting files \$TOOOLD days old." # delete old files find \$DIR -type f -mtime +\$TOOOLD \( -name 'http_*.*.log.bz2' -or -name "resin_access_log.*.bz2" -or -name "access.*.log.bz2" -or -name "error.*.log.bz2" -or -name "resin.std*.log.*.bz2" -or -name "access.*.bz2" -or -name "error.*.bz2" -or -name "*_access.*.bz2" -or -name "*_error.*.bz2" -or -name "resin.log.*.bz2" -or -name "std*.log.*.bz2" -or -name "catalina.*.log.bz2" -or -name "host-manager.*.log.bz2" -or -name "localhost.*.log.bz2" -or -name "manager.*.log.bz2" -or -name "webagent.*.log.bz2" \) -print -exec rm {} \; echo echo "logrotate: Compressing files \$COMPOLD days old." # bzip2 non-current files find \$DIR -type f -mtime +\$COMPOLD \( -name 'http_*.*.log' -or -name "resin_access_log.*" -or -name "access.*.log" -or -name "error.*.log" -or -name "resin.std*.log.*" -or -name "access.*" -or -name "error.*" -or -name "*_access.*" -or -name "*_error.*" -or -name "resin.log.*" -or -name "std*.log.*" -or -name "catalina.*.log" -or -name "host-manager.*.log" -or -name "localhost.*.log" -or -name "manager.*.log" -or -name "webagent.*.log" \) ! -name "*.bz2" -print -exec bzip2 {} \; echo "logrotate: Complete." exit 0 EOF fi