maniu@securebrain.com:~/script# vi dircheck.sh



#!/bin/sh
# usando md5sum sulle directory definite in $DIR1, $DIR2 e $DIR3,
# questo script esegue il checksum memorizzando
# le firme dei file all'interno dello script stesso.
# e' possibile aggiornare le firme in ogni momento
# non aggiungere ulteriori righe allo script

PERCORSO=`pwd`
DIR1=`find /etc/* -type f`
# con * non vedo i .
DIR2=`find /sbin/* -type f`
# in questo modo anche i link vengono esclusi
DIR3=`find /usr/sbin/* -type f` IFS=$'\n' RIGA=`wc -l $PERCORSO/dircheck.sh |cut -d\ -f 1`
# cosi' capisco se e' gia' stato generato lo storage

# se la linea 49 e' empty (lo storage non esiste)
# o se si vuole cambiare lo storage di riferimento crea uno storage
touch /tmp/mdchecksum
if [ "$RIGA" -le 49 ]
 then
    echo "creo lo storage di riferimento"
    for i in $DIR1 $DIR2 $DIR3
        do md5sum $i >> $PERCORSO/dircheck.sh
    done
 else
    echo -ne "Vuoi aggiornare lo storage di riferimento ? [y/n]: "
    read yn
    if [ $yn = y ]
     then head -n 49 $PERCORSO/dircheck.sh > /tmp/scriptC; cp /tmp/scriptC $PERCORSO/dircheck.sh ; rm -rf /tmp/dircheck.sh;
       for i in $DIR1 $DIR2 $DIR3
          do md5sum $i >> $PERCORSO/dircheck.sh
       done
    else echo "eseguo il checksum sul vecchio storage"
    fi
fi
GHGH=`wc -l $PERCORSO/dircheck.sh |cut -d\ -f 1`
# linee complessive dello script
CHCH=`grep -n storage $PERCORSO/dircheck.sh |tail -1 |cut -d: -f 1`
# linea in cui si trovano i files
FHFH=$(($GHGH - $CHCH))
# le linee dello script - il codice = linee storage
MDFILE=`tail -n "$FHFH" $PERCORSO/dircheck.sh`
# printa solo lo storage
for f in $MDFILE
 do
  echo $f >> /tmp/mdchecksum
done
md5sum -c /tmp/mdchecksum
rm -rf /tmp/mdchecksum
exit
storage




:q!