lwzm
3/8/2015 - 11:22 AM

backup_leases

backup_leases

#!/bin/sh
LEASES_FILE="dhcpd.leases~"

mkln() {
    if [ $(ls -l "$LEASES_FILE" | cut -f 2 -d ' ') -eq 1 ] ; then  # if is not backed-up
        DATE="$(date '+%G%m%d-%H%M%S')"
        ln "$LEASES_FILE" "$DATE"
        echo "$LEASES_FILE" '->' "$DATE"
    fi
}

mkln

while true ; do
    if inotifywait -e delete . ; then

        while true ; do
            if [ -f "$LEASES_FILE" ] ; then
                mkln
                break
            else
                echo "$DATE" error
                sleep 1
            fi
        done

    else
        echo inotifywait error!
    fi
done