1
|
#!/bin/sh
|
2
|
|
3
|
help="# ARGS: number of files to keep, [email address]\n
|
4
|
# usage: flush files from a folder except a number equal to argument.\n
|
5
|
# It only prints a warning if scripts-utils.sh is not imported in order to be used
|
6
|
# from the terminal."
|
7
|
|
8
|
# Check if scripts-utils.sh is imported.
|
9
|
if [ -z $scripts_utils ] ; then
|
10
|
echo "Import of scripts-utils.sh required."
|
11
|
. scripts-utils.sh
|
12
|
fi
|
13
|
|
14
|
check_arguments $# 1 "$help"
|
15
|
|
16
|
backups_number=`ls | wc -l`
|
17
|
let "number_of_backups_to_delete = backups_number - $1" > /dev/null
|
18
|
|
19
|
if [ $number_of_backups_to_delete -gt 0 ] ; then
|
20
|
ls | head -$number_of_backups_to_delete | xargs rm
|
21
|
else
|
22
|
if [ ! -z $2 ] ; then
|
23
|
dir=`pwd`
|
24
|
echo "There are not enough files in $dir to Flush it. Check if backup script works fine." | mail -s "[db] $dir has a backup problem" $2
|
25
|
fi
|
26
|
fi
|