SuSEサーバー上のディレクトリにファイルをFTPで転送するIPカメラがあります。
次のことを行うためのシェルスクリプトを作成しようとしています。
for every file in a directory;
use image compare to check this file against the next one
store the output in a file or variable.
if the next file is different then
copy the original to another folder
else
delete the original
end for
プロンプトで次を実行すると、これが生成されます。
myserver:/uploads # imgcmp -f img_01.jpg -F img_02.jpg -m rmse > value.txt
myserver:/uploads # cat value.txt
5.559730
5.276747
6.256132
myserver:/uploads #
コードに間違った負荷があることはわかっています。私が抱えている主な問題は、スクリプトからimgcmpを実行し、そこから値を抽出することです。私にはわかりにくいかもしれないので、明らかなことを指摘してください。
FILES=/uploads/img*
declare -i value
declare -i result
value = 10
shopt -s nullglob
# no idea what the above even does #
# IFS=.
# attempt to read the floating point number from imgcmp & make it an integer
for f in $FILES
do
echo "doing stuff w/ $f"
imgcmp -f 4f -F 4f+1 -m rmse > value.txt
# doesn't seem to find the files from the variables #
result= ( $(<value.txt) )
if [ $result > $value ] ; then
echo 'different';
# and copy it off to another directory #
else
echo 'same'
# and delete it #
fi
if $f+1 = null; then
break;
fi
done
上記を実行すると、エラーが発生cannot open /uploads/img_023.jpg+1
し、value.txtの猫を実行しても何も表示されないため、すべてのファイルが同じであると表示されます。
問題がどこにあるかはわかっていますが、imgcmpの出力(スクリプト内から実行)を抽出し、それを比較できる変数に取り込むために実際に何をすべきかわかりません。