Steefmaester

Verification MD5

Apr 9th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.43 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. REP="."
  4. NOM_BD="md5.db"
  5.  
  6. if [ -f $NOM_BD ]; then
  7.     : NOOP
  8. else
  9.     sqlite3 $NOM_BD "create table sig(lig varchar(255),md char(32),fic varchar(255));"
  10. fi
  11.  
  12. find "$REP/" -iname '*' -not -name "$NOM_BD" -type f -exec md5sum {} >md.md5 \;
  13.  
  14.  sqlite3 $NOM_BD "delete from sig;"
  15.  
  16. while read ligne
  17. do
  18.     sql="INSERT into sig(lig,md,fic) VALUES ('$ligne',substr('$ligne',1,32),trim(substr('$ligne',35)));"
  19.     sqlite3 $NOM_BD "$sql"
  20. done < md.md5
  21.  
  22. rm -f md.md5
  23. sqlite3 -header -column $NOM_BD "SELECT * FROM sig;"
  24.  
  25. #! /bin/bash
  26.  
  27. REP="."
  28. BKP_PATH="/chemin/vers/bkp"
  29. NOM_BD="md5.db"
  30.  
  31.  
  32. VERT="\\033[1;32m"
  33. NORMAL="\\033[0;39m"
  34. ROUGE="\\033[1;31m"
  35. JAUNE="\\033[1;33m"
  36.  
  37. nb_lignes=$((`sqlite3 $NOM_BD "SELECT count(*) from sig"` -1))
  38. i=0
  39. while [ "$i" -le "$nb_lignes" ]; do
  40.     echo -n "$(($i + 1))~"
  41.     ligne=`sqlite3 $NOM_BD "SELECT * FROM sig LIMIT $i,1"`
  42.  
  43.     fic= `echo $ligne | cut -d"|"-f3`
  44.     md5_enreg= `echo $ligne | cut -d"|" -f3`
  45.  
  46.     if [[ -f $fic ]]; then
  47.         md5_actuel=` md5sum "$fic"|cut -d" " -f1`
  48.         echo -n "$fic : $md5_enreg = $md5_actuel"
  49.         if [ $md5_actuel == $md5_enreg ]; then
  50.             echo -e " : ${VERT}OK${NORMAL}"
  51.         else
  52.             echo -e " : ${ROUGE}KO - cp -f $BKP_PATH/$fic $fic${NORMAL}"
  53.         fi
  54.     else
  55.         echo -e "$fic : md5_enreg = --- : ${JAUNE}KO - le fichier n'existe plus!!!${NORMAL}"
  56.     fi
  57.     i=$(($i + 1))
  58. done
Advertisement
Add Comment
Please, Sign In to add comment