We have a directory of files which need to be renamed and moved to another directory based on filename information in a cvs file.
The contents of the cvs file are:
A10324687,ahgk1ff0023
A10324698,cru1ff0129
The source folder has the following hierarchy:
/Server/Archive/A/AHGK1/AHGK1FF0001_0200/ahgk1ff0023.pdf
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.ai
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.pdf
/Server/Archive/B/BFKR3/BFKR3LC0001_0200/bfkr3lc0018.pdf
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.ai
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.pdf
The results of the script moves and renames ahgk1ff0023* to:
/Server/Art/A10324687_ahgk1ff0023.pdf
The number of characters in the filename and path vary.
Therefore, I thought it necessary to use a find function with input from the csv file which has the basename minus extensions.
The following script performs well on local files but crawls when run on files
from network shares. Any suggestions?
Code:
#!/bin/bash
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
#Directory for source files to br moved and renamed
src=/Volumes/Serve/Archive
#Directory in which the files are move to
dest=/Volumes/Serve/Art/
IFS=','
while read new old; do
ai=$(find $src -name $old.ai)
pdf=$(find $src -name $old.pdf)
#Following varible is used to stamp the pdf file with the "New" number from the csv input
pdfout="$dest$new"_"$(basename $pdf)"
stamper=/Users/Admin/Desktop/TMP/stamp.pdf
ait=$(find $src -name $old.ait)
eps=$(find $src -name $old.eps)
tiff=$(find $src -name $old.tiff)
tif=$(find $src -name $old.tif)
psd=$(find $src -name $old.psd)
fh8=$(find $src -name $old.fh8)
fh9=$(find $src -name $old.fh9)
noExt=$(find $src -name $old)
#This is where the pdf files get stamped with the "New" number
echo $new" -> "$old" -> "$pdfout$(basename $pdf) >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
gs -q -sDEVICE=pdfwrite -o $stamper -c "<< /PageSize [792 612] >> setpagedevice 18 586 moveto /Helvetica-Bold_Italic findfont 14 scalefont setfont ("$new") show"
pdftk $pdf stamp $stamper output $pdfout verbose | grep .pdf$ >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
rm -f -v $pdf >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
#The following moves the remaining file types if they exist.
mv -v $ai $dest${new}'_'${old}.ai >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $ait $dest${new}'_'${old}.ait >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $eps $dest${new}'_'${old}.eps >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $tiff $dest${new}'_'${old}.tiff >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $tif $dest${new}'_'${old}.tif >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $psd $dest${new}'_'${old}.psd >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $fh8 $dest${new}'_'${old}.fh8 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $fh9 $dest${new}'_'${old}.fh9 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $noExt $dest${new}'_'${old} >> /Volumes/Serve/Users/Admin/Logs/SKU.log
done < /Users/Admin/Desktop/List.csv