Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. for i in "$@"; do
  4. file=$i
  5.  
  6. filename=$(basename "$file")
  7. fingerprintfile="/tmp/$filename.md5"
  8.  
  9. if [ ! -f $file ]; then
  10. echo "ERROR: $file does not exist - aborting"
  11. fi
  12.  
  13. filemd5=`md5sum $file | cut -d " " -f1`
  14.  
  15. if [ -z $filemd5 ]; then
  16. echo "The file $file is empty - aborting"
  17. fi
  18.  
  19. if [ -f $fingerprintfile ]; then
  20.  
  21. savedmd5=`cat $fingerprintfile`
  22.  
  23. if [ -z $savedmd5 ]; then
  24. echo "The file $filename is empty - aborting"
  25. fi
  26.  
  27. if [ "$savedmd5" = "$filemd5" ]; then
  28. echo "File $filename hasn't been changed"
  29. else
  30. echo "File $filename has been changed"
  31. echo $filemd5 > $fingerprintfile
  32. fi
  33. else
  34. echo $filemd5 > $fingerprintfile
  35. echo "File $filename is new one"
  36. fi
  37.  
  38. done
Add Comment
Please, Sign In to add comment