#!/bin/bash # # prune.sh - prune backups, weed out any entries older than the most recent 3 # # 20101013 - initial version (mth) # user="$1" if [ -z "$1" ]; then echo "ERROR! Must be called with a user argument." exit 1 fi if [ -e "/backup/$user" ]; then cd /backup/$user bckcnt="`/bin/ls -1A | wc -l`" if [ "$bckcnt" -gt 3 ]; then let removal=$bckcnt-3 files="`/bin/ls -1A | head -$removal`" rm -f $files fi fi exit 0