cvsファイルのファイル名情報に基づいて、名前を変更して別のディレクトリに移動する必要のあるファイルのディレクトリがあります。 CVSファイルの 内容は以下のとおりです。
A10324687、
A10324698、ahgk1ff0023 cru1ff0129bash cvsファイルのデータから解析されたファイルを見つけて移動する
ソースフォルダ以下の階層があります。スクリプトが動くの
/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
結果をして
ahgk1ff0023.pdf to: /Server/Art/A10324687_ahgk1ff0023.pdf
の名前を変更
ファイル名とパスの文字数が異なります。 したがって、ベース名から拡張子を引いたcsvファイルの入力でfind関数を使用する必要があると考えました。 次のスクリプトはローカルファイルに対しては正常に動作しますが、ネットワーク共有からのファイル で実行するとクロールします。助言がありますか?
#!/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
すべてのファイル名をターゲットとしたfindを1つに減らします。つまり、 'find $ src -name $ old.psd -name $ old.tif ....'これを '|ファイル名を読んでいる間。 * .pdfのcase $ {filename}を実行します).... ;; * .tif)... ;;エサック。ファイル名にスペースやその他の英数字以外の文字が含まれることが予想される場合は、-print0オプションとxargsを参照してください。そのコンボについての投稿は100件あります。がんばろう。 – shellter