Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. noofscripts=$(pgrep phar.sh | wc -l)
  4.  
  5. if [[ $noofscripts -gt 2 ]]; then
  6. echo "Can not run more than one process at a time"
  7. exit
  8. fi
  9.  
  10.  
  11. if expr match "$1" "$2">/dev/null; then
  12. echo "error"
  13. exit
  14.  
  15. elif expr match "$2" "$1" >/dev/null; then
  16. echo "error"
  17. exit
  18. fi
  19.  
  20. #If a user omits either of the two arguments it displays a helpful message and terminates.
  21.  
  22. if [ $# -ne 2 ]; then
  23.  
  24. echo "usage: Phar image_path archive_path"
  25.  
  26. Exit
  27.  
  28. fi
  29.  
  30.  
  31.  
  32. #If the archive directory does not exist the scripts creates it.
  33.  
  34. if [ ! -d $2 ]; then
  35.  
  36. mkdir $2
  37.  
  38. fi
  39.  
  40.  
  41.  
  42. #If the image source directory does not exist the script reports this error and terminates.
  43.  
  44. if [ ! -d $1 ]; then
  45.  
  46. echo "source directory does not exist"
  47.  
  48. exit
  49.  
  50. fi
  51.  
  52.  
  53.  
  54. #Loops through every file in $1 that matches 'IMG_[0-9][0-9][0-9][0-9]\.JPG'.
  55.  
  56. for file in $(find $1 -name 'IMG_[0-9][0-9][0-9][0-9]\.JPG');do
  57.  
  58. filename=${file: -12}
  59.  
  60. echo "lll"
  61.  
  62.  
  63.  
  64. #If statement is used to check if there is a file in $2 that matches filename. And if it does not it copies to $2.
  65.  
  66. #readlink gets the absolute path of the duplicate and sends it duplicate text file.
  67.  
  68. #if there is already a file with that name but not identical it adds .jpg to avoid overwriting it.
  69.  
  70. if ([ ! -e ${2}/${filename} ]);
  71.  
  72. then cp -- $file $2
  73.  
  74. echo "$filename is being copied";
  75.  
  76. else
  77.  
  78. if cmp $file $2/$filename; then
  79.  
  80. echo "rrrr"
  81.  
  82. readlink -f $file >> $2/duplicates.txt
  83.  
  84. else cp $file "$file.JPG"
  85.  
  86. cp $file.JPG $2
  87.  
  88. fi
  89.  
  90. fi
  91.  
  92. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement