Projet

Général

Profil

Paste
Télécharger (882 octets) Statistiques
| Branche: | Révision:

root / bin / flush-files.sh @ 7c435b4e

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
# Must not be quoted to avoid problem with ((…))
17
backups_number=$(ls | wc -l)
18
number_of_backups_to_delete=$((backups_number - $1))
19

    
20
if [ "${number_of_backups_to_delete}" -gt 0 ] ; then
21
    ls | head "-${number_of_backups_to_delete}" | xargs rm
22
else
23
    if [ -n "$2" ] ; then
24
        dir=$(pwd)
25
        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"
26
    fi
27
fi