All pastes #743231 Raw Edit

Stuff

public text v1 · immutable
·published 2007-10-20 07:29 UTC
rendered paste body
Copy the following beginning with the "#!/bin/bash" line into a file such as w2bldclean_check.sh in your $HOME.
After that:
 chown username.username filname
 chmod 700 filename
 crontab -e
 enter in and save: 0 2 * * * /home/<yourusername>/<scriptname>

#!/bin/bash

//Created by Ben Fisher
//2007-Oct-20
//Delete all but the five most recent directories in a path, for warlock2 builds.

//Pull directories, stat for mtime, sort numerically, and store (overwrite, not append, each time).
find /PATH/TO/BUILDS -maxdepth 1 -type d -print0 | xargs -0 -i stat -c "%y %n" {} | sort -nr > ~/.w2bldclean_check
//Number of directories total.
lines=`cat ~/.w2bldclean_check | wc -l`
//Number of directories minus 5 (from the correctly time-sorted list).
rmlines=$(($lines - 5))
//Sorted numerically in reverse, so tail by a value equal to 5 less than the total in the list, and then remove those.
cat ~/.w2bldclean_check | tail -`echo $rmlines` | cut -d ' ' -f 4 | xargs -i rm -Rf {}
//If less than 5, this does nothing.