我有一个 IP 摄像机,可以将文件通过 ftps 传输到我的 SuSE 服务器上的一个目录。
我正在尝试编写一个 shell 脚本来执行以下操作:
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
,并且执行 cat of value.txt 没有显示任何内容,因此所有文件都显示为相同。
我知道问题出在哪里,但我不知道我实际上应该做什么来提取 imgcmp 的输出(从脚本中运行),然后将它放入一个我可以比较的变量中。