#!/bin/sh # Ce script liste les derniers passages des disques # d'externalisation. # Selon les options fournies, il peut aussi mettre à # jour le listing. # Config EXTERNAL_DISK_UUID="394165d5-b1dc-42a1-aa2e-006516f8e33f" DATABASE="/root/disques-externalisation_timestamp.lst" CORRESPONDANCE="/root/disques-externalisation_correspondance.lst" # Initialisation MISE_A_JOUR=0 SILENCIEUX=0 # affiche le message d'aide usage() { cat <&2 exit 1 ;; esac done shift $( expr $OPTIND - 1 ) if [ "$MISE_A_JOUR" -gt 0 ]; then # On récupère l'id du disque # TODO : alerte si plusieurs devices correspondants ? if [ ! -e "/dev/disk/by-uuid/$EXTERNAL_DISK_UUID" ]; then exit 1 fi DISQUE_ID=$( find /dev/disk/by-id -lname "$( readlink /dev/disk/by-uuid/$EXTERNAL_DISK_UUID )" | head -n 1 | xargs basename ) # ...et on l'ajoute au listing TMPFILE=$( mktemp ) cat $DATABASE | grep -v "$DISQUE_ID" | grep -v "^$" >$TMPFILE printf "%d\t%s\n" "$( date +%s )" "$DISQUE_ID" >>$TMPFILE cat "$TMPFILE" | sort -n >$DATABASE rm -f "$TMPFILE" fi if [ "$SILENCIEUX" -eq 0 ]; then TS_NOW=$( date +%s ) # Listing avec nb de jours depuis dernière mise à jour printf " Age Label\n" cat "$DATABASE" | while read LINE; do TS=$( echo $LINE | awk '{ printf $1 }' ) ID=$( echo $LINE | awk '{ printf $2 }' ) LABEL=$( test -f "$CORRESPONDANCE" && cat "$CORRESPONDANCE" | sed -n "s/^$ID[[:space:]]\+\(.*\)$/\1/p" ) # Affichage du nombre de jours printf "%3dj " "$(( ( $TS_NOW - $TS ) / 86400 ))" # Affichage du label de la table de correspondance (ou, si absent, de l'Id) if [ "$LABEL" == "" ]; then LABEL="$ID" fi printf "%s\n" "$LABEL" done fi