Image Archive Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Image Archive Script
# 1  
Old 11-23-2015
Image Archive Script

Hello,
I am working through a test Linux script from a website, and am running into some issues. The point of the script is to find image files throughout the system, copy them to one centralized directory,ignore duplicate images with the same name, and output a text file of all the images copied.
The script is below.


Code:
#!/bin/sh
if [ ! -d $1 ] ; then 
echo "Exiting due to non-existing $1"
exit #Check if source drive exists#
#
fi


if [ ! -d $2 ] ; then mkdir $2 #checking if destination directory exists #

else  echo -e "Usage::# phar image_path archive_path" #outputs helpful error message #

find $1 -name "IMG_*.JPG" # find files #
fi

for i in $1; do  #finds duplicate files and copies the non duplicate files.
    find $i -type f -name 'IMG_*.jpg' -exec cp {} $2 \;
    for j in $2; do
        find $2 -type f -name $i | while read filename; do if test "$i"="$j"; then mv $i new_filename; fi done
    done
done 

#then
#    mv -f "IMG_*.JPG.JPG"
#
#    else if  diff -q $file1 $file2  ; then echo "files are the same" ; exit # Checks if two files are the same.#
#    fi

# output a list of the files copied and moved
# readlink -f.-name"iMG".JPG>files_moved.txt

Thanks for the help.
# 2  
Old 11-24-2015
The issues are WHAT?

Some comments:
- Unless you have good reasons (which?), why do you limit the execution to the sh shell?
- Your usage/error msg comes if $2 exists - is that expected behaviour?
- What are you using the results of the first find for?
- Do you want to copy or move the files?
- Do you know about the -v option to both cp and mv?

Last edited by RudiC; 11-25-2015 at 04:23 AM.. Reason: typo
# 3  
Old 11-24-2015
-The example I was following was limiting the function to a bash shell only
- I want it to output an error message if both directories exist to tell the user how to run the program
- I am using the first find to find all the images that match this format IMG_0000.JPG
- I want to copy the files into an archive folder without any sub folders.
- No
# 4  
Old 11-24-2015
Heya ComSciguy17

What already has been said:
1. The usage message comes if "$2" is passed (See 3.)
Anyway, the user passes a target dir, sees the usage message, and a list of files found in $1 - that list is not -- cannot be -- used -- later on again, --> unrequired/obsolete.

In addition:
2. Use more (often) quotes around variables (imagine file names with spaces, though not wanted, but might happen anyway.
3.
[ -d "$1" ] Checks if $1 is a directory
[ -z "$1" ] Checks if an argument has been passed at all
If no argument has been passed, say so, dont use the (unescaped) variable-name, as that part will be empty if no argument has been passed.
Likewise for the destination.
Example:
Code:
[ -z "$2" ] && echo "Usage: ${0##*/} SEARCHDIR TARGETDIR" && exit 1
[ ! -d "$2" ] && ! mkdir -p "$2" && echo "Could not create destination: \"$2\"" && exit 1

4. Place the results of find into variables (lists), as that could help to remove duplicates.
Some of the find commands, look (to my eyes) unused...


Last but not least, since not really relevant, try to stick to one coding style, i see like 3 or even 4 different styles.
Makes the reading easier (specialy without syntax highlighting).
But maybe you just need to figure your coding style first, so no worries. Smilie

And to repeat RudiC, since i dont feel that has been provided yet...
Quote:
The issues are WHAT?
Elaborate, dont just say what you want, but what is, what you have tried to fix, where you stuck?

Have a nice evening.
hth
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. Shell Programming and Scripting

Need a little help with my first shell script. Basic image resize script...

Hey everyone, just now joined because I didn't want to go onto Ubuntu forums and start asking about how to write shell scripts. Seems like this is a pretty active forum for exactly what I need. I'm trying to modify a shell script I found online, the end goal is to have it find all files in the... (9 Replies)
Discussion started by: mozzles
9 Replies

3. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

4. Windows & DOS: Issues & Discussions

Archive Unix script to Batch script

Hi All, I have a requirement to archive processed file and retain the archive based on the quantity.. but this is in windows. I have written a drafted shell script, and would like to have it translated into Batch script.. Please... Below is the drafted shell script ... (2 Replies)
Discussion started by: Dave Null
2 Replies

5. Shell Programming and Scripting

need help archive script

Hi all, I am new to linux and scripting so please forgive me. I need to create a script that will archive files but the max size of the archive need to be 500mb or under. I know about the archiving with parts but i want all the archives as individual archives. Can anyone point me in the correct... (7 Replies)
Discussion started by: craig0
7 Replies

6. Shell Programming and Scripting

Need some help with an archive script

I'm not sure how to solve the $month-1 thingy or the foreach sentence, so I need some help./* folders = folder1 folder2 folder3 folder4 folder5 */ month=`date +%m` if($month == 01) { prev_month = 12 } else { prev_month =... (7 Replies)
Discussion started by: JKMlol
7 Replies

7. Shell Programming and Scripting

script help .. archive

Hi All We have a landing directory where source system puts files.There are variable number of files and the file names are also varying.Each files successful transmission is identified by a .done file.If file name is xyz.dat then the confirmation file will be xyz.dat.done. I want to... (1 Reply)
Discussion started by: dr46014
1 Replies

8. Shell Programming and Scripting

Archive script

hi guru, can advise how to construct a housekeeping script using perl for the following ? find /var/tmp/logs -name "si*" -type f -exec gzip -f {} \; find /var/tmp/logs -name "*.gz" -type f -exec mv -f {} /var/tmp/log \; I found out those are not working in shell at when put them on... (1 Reply)
Discussion started by: rauphelhunter
1 Replies

9. UNIX for Advanced & Expert Users

Create an Ignite image on tape from Online IgniteUX image

Hi, (HP-UX 11.11) I need to create a tape image of an igniteUX image created on our igniteUX server. That is to say. I have a "Online" image of the igniteUX of the targeted system but I now need to copy it to a useable TAPE (igniteUX) image so i can build an other server from it that is not... (3 Replies)
Discussion started by: Andrek
3 Replies
Login or Register to Ask a Question