Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- noofscripts=$(pgrep phar.sh | wc -l)
- if [[ $noofscripts -gt 2 ]]; then
- echo "Can not run more than one process at a time"
- exit
- fi
- if expr match "$1" "$2">/dev/null; then
- echo "error"
- exit
- elif expr match "$2" "$1" >/dev/null; then
- echo "error"
- exit
- fi
- #If a user omits either of the two arguments it displays a helpful message and terminates.
- if [ $# -ne 2 ]; then
- echo "usage: Phar image_path archive_path"
- Exit
- fi
- #If the archive directory does not exist the scripts creates it.
- if [ ! -d $2 ]; then
- mkdir $2
- fi
- #If the image source directory does not exist the script reports this error and terminates.
- if [ ! -d $1 ]; then
- echo "source directory does not exist"
- exit
- fi
- #Loops through every file in $1 that matches 'IMG_[0-9][0-9][0-9][0-9]\.JPG'.
- for file in $(find $1 -name 'IMG_[0-9][0-9][0-9][0-9]\.JPG');do
- filename=${file: -12}
- echo "lll"
- #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.
- #readlink gets the absolute path of the duplicate and sends it duplicate text file.
- #if there is already a file with that name but not identical it adds .jpg to avoid overwriting it.
- if ([ ! -e ${2}/${filename} ]);
- then cp -- $file $2
- echo "$filename is being copied";
- else
- if cmp $file $2/$filename; then
- echo "rrrr"
- readlink -f $file >> $2/duplicates.txt
- else cp $file "$file.JPG"
- cp $file.JPG $2
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement