1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   | #! /bin/bash
ISO_MOUNTPATH="/mnt/graveur"
ISO_REMOTEPATH=""
USER_LIST="/home/sauvegarde/sauv_users.txt"
if [ -r ${USER_LIST} ]
then
        USERS=`cat ${USER_LIST}`
else
        echo "Impossible de lire ${USER_LIST}"
        exit 1
fi
USERS=`cat ${USER_LIST}`
DIRS=""
DIR_LIST=""
for USERNAME in $USERS
do
        ln -s -f "/home/$USERNAME" /home/links/
        REMOTE_COMPUTER=`grep /mnt/$USERNAME /etc/fstab | awk -F ' ' '{print $1}' | awk -F '/' '{print $3}'`
        IS_ACTIVE=`nmblookup ${REMOTE_COMPUTER} | grep failed | wc -l`
        if [ ${IS_ACTIVE} -lt 1 ]
        then
                mount /mnt/$USERNAME
        else
                echo "Impossible de se connecter à ${REMOTE_COMPUTER}"
                continue
        fi
        DIR_LIST="/home/sauvegarde/${USERNAME}.dir"
        if [ -r ${DIR_LIST} ]
        then
                DIRS=`cat ${DIR_LIST}`
        else
                echo "Impossible de lire ${DIR_LIST}"
                continue
        fi
        for DIR in $DIRS
        do
                if [ -d /mnt/$USERNAME/$DIR ]
                then
                        mkdir -p /home/$USERNAME/$DIR
                        cd /home/$USERNAME/$DIR
                        cp -r "/mnt/$USERNAME/$DIR/"* .
                else
                        echo "Impossible de copier /mnt/$USERNAME/$DIR"
                        continue
                fi
        done
        sync
        umount /mnt/$USERNAME
        sleep 5
done
LABEL=`date +"%Y_%m_%d"`
ISO_FILENAME="/home/sauvegarde/${LABEL}.iso"
mkisofs -f -R -r -J -V "$LABEL" -o "${ISO_FILENAME}" /home/links
REMOTE_COMPUTER=`grep ${ISO_MOUNTPATH} /etc/fstab | awk -F ' ' '{print $1}' | awk -F '/' '{print $3}'`
IS_ACTIVE=`nmblookup ${REMOTE_COMPUTER} | grep failed | wc -l`
if [ ${IS_ACTIVE} -lt 1 ]
then
        mount ${ISO_MOUNTPATH}
else
        echo "Impossible de se connecter à ${REMOTE_COMPUTER}"
        exit 1
fi
cp "${ISO_FILENAME}" "${ISO_MOUNTPATH}/${ISO_REMOTEPATH}"
sync
touch "${ISO_MOUNTPATH}/${ISO_REMOTEPATH}/gravure_ok.txt"
sync
umount ${ISO_MOUNTPATH}
#rm -f "${ISO_FILENAME}"
rm /home/links/* | 
Partager