Search code examples
bashunixsolaris

Log rotation (zipping/deleting) script in Solaris


Had same log rotation files in linux environment and there they work. In Solaris I have problems with running those scrips:

The main purpose of scripts is to delete all logs that are older than 30 days and zip all logs that are older than 5 days. -not -name is used because I want to operate only on rotated log files, for example something.log.20181102 because .log files are current ones and I don't want to touch them.

#!/bin/bash

find ./logs -mindepth 1 -mtime +30 -type f -not -name "*.log" -delete
find ./logs -mtime +5 -not -name "*.log" -exec gzip {} \;

Problems occur with -mindepth and -not because it gives errors:

find: bad option -not
find: [-H | -L] path-list predicate-list

Based on search I have to use -prune somehow in the find, but I am not too sure how to.


Solution

  • With the help of @Danek Duvall and with some searching I got it working:

    find ./logs -mtime +30 -type f ! -name "*.log" -exec rm -f {} \;
    find ./logs -mtime +5 ! -name "*.log" -exec gzip {} \;
    

    It deletes all log files that are older than 30 days and then zips the ones that are older than 5 days.