1

I have to get pictures from a folder – with subfolders which are updated automatically – with their extensions.

These files have to be copied in a folder where a website based on PHP will edit them (by renaming and creating an XML file) to be downloadable and integrated in an XML feed.

Because of the rename function of the script, when I perform the copy gain, all the files are duplicated, because the script has renamed the original ones already.

I've tried a few things with rsync but I'm looking for something more powerful because I can't copy files with an external "history".

#!/bin/bash
find  '/home/name/picture' -name '*.jpg' | while read FILE ; do rsync --backup  --backup-dir=incremental --suffix=.old  "$FILE" /var/www/media ; done
wget --spider 'http://myscript.php' ; 
#exit 0

PS: As a little addition, I'd like to replace '.' with a 'space' just after the *.jpeg copy. My PHP script has some problem to define files with comma because of the extension. I'm finking about a command with find – like I did before – with a sed function? Is that a good idea?

8
  • 2
    So, am I reading this right, when you copy with rsync, it creates all the files again, because they've been renamed, and you get duplicates?
    – slhck
    Nov 14, 2011 at 16:17
  • Yes slhck. I'm sorry it's quite hard to explain clearly with my bad english. :)
    – Benoitt
    Nov 14, 2011 at 22:50
  • No prob, that's why I asked :) — So I was thinking, maybe the PHP tool could just make a list of which files it has renamed. You could then exclude those from the rsync command.
    – slhck
    Nov 14, 2011 at 22:55
  • The thing is a didn't develop the php website. I've try to desactivate few fonctions like renaming but it doesn't work. I've also contact the author but he refuse to change anything to prevent bugs on uploading. ;)
    – Benoitt
    Nov 15, 2011 at 0:50
  • Do you know what the renaming convention is? In other words, the files get uploaded and renamed, would your script be able to predict what the new names would be? I suppose the other way to do it is keep track locally of any files that have been successfully uploaded and exclude them (or move them out of the source folder)
    – Paul
    Nov 15, 2011 at 2:22

1 Answer 1

0

You can use the following:

#!/bin/ksh
DEST_DIR=/destination
HIST_DIR=/images_bck
SOURCE_DIR=/images

find ${SOURCE_DIR} -name "*.jpg" >${HIST_DIR}/tmp.file
exec 3<${HIST_DIR}/tmp.file

while read file <&3;do
  file_name=$(basename "${file}")
  if [ ! -f "${HIST_DIR}/${file_name}.old" ];then
    cp -p "${file}" "${HIST_DIR}/${file_name}.old"
    cp "${file}" "${DEST_DIR}"
  fi
done
exec 3<&-
[ -f ${HIST_DIR}/tmp.file ] && rm -f ${HIST_DIR}/tmp.file

For new users;

sudo apt-get install ksh

it's a kornshell, after change DEST_DIR , HIST_DIR, SOURCE_DIR and do

ksh -v ./MySuperScript.ksh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .