0

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の出力(スクリプト内から実行)を抽出し、それを比較できる変数に取り込むために実際に何をすべきかわかりません。

4

1 に答える 1

1
FILES=/uploads/*

current=
for f in $FILES; do
  if [ -z "$current" ]; then
    current="$f"
    continue
  fi
  next="$f"
  echo "<> Comparing $current against $next"
  ## imgcmp will return non-0 if images cannot be compared
  ## and print an explanation message to stderr;
  if result=$(imgcmp -f $current -F $next -m rmse); then
    echo "comparison result: " $result
    ## Checking whether the first value returned
    ## is greater than 10
    if [ "$(echo "$result" | awk '$1 > 10 {print "different"}')" = "different" ]; then
      echo 'different';
      # cp -v $current /some/other/folder/
    else
      echo 'same'
      # rm -v $current
    fi
  else
    ## images cannot be compared... different dimensions / components / ...
    echo 'wholly different'
    # cp -v $current /some/other/folder/
  fi
  current="$next"
done
于 2013-03-14T09:15:14.070 に答える