OSX auto cleanup tmp ignore dir

Was putting some project related configs into the OS X /tmp directory, but found it was deleted. Turns out OS X has system scheduled cleanup job for the tmp dir. The config is under ‘/etc/defaults/periodic.conf‘.

I was first trying to leverage the provided ‘daily_clean_tmps_ignore’ parameter to exclude my directory but found not working, have to go to the source shell script to see why. The cleanup script locates in : ‘/etc/periodic/daily/110.clean-tmps’ which will go to the ‘/tmp’ dir and find command to get all the files that are 3 days old(atime, mtime, ctime) and not in the ignore list. So all the names we specified in the ‘daily_clean_tmps_ignore’ will be prefix the ‘! -name $pattern’ so that the $pattern could be excluded. However what i am trying to achieve here is for a directory and all its sub-files/dirs where using the -name is not enough.

We can use the -path option but we cannot add that thru configuration file.

Finally i decided to change the system script to achieve the ignoring by add a -name $pattern -prune option. After modification, it becomes:

 rc=$(for dir in $daily_clean_tmps_dirs
                do  
                    [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
                        find -dx . -name 'MyDir' -prune -fstype local -type f $args -delete $print
                        find -dx . -name 'MyDir' -prune -fstype local ! -name . -type d $dargs -delete $print
                    } | sed "s,^\\.,  $dir,"
                done | tee /dev/stderr | wc -l)
            [ -z "$print" ] && rc=0
            [ $rc -gt 1 ] && rc=1
            set -f glob

A SO reference about -prune.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s