我有一台IP摄像机,可以将文件ftps文件传输到我的SuSE服务器上的某个目录。bash shell脚本在两个JPG上运行imgcmp并存储“不同的”
我试图写一个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
和做value.txt的猫说明不了什么,所以所有的文件显示为相同。
我知道问题出在哪里,但我不知道我应该怎么做才能提取imgcmp的输出(从脚本中运行),然后将它变成一个变量,我可以将其与。
你有一些错别字(4f而不是$ f)。你是否尝试过使用basename来提取文件名,使用sed来提取名称的数字部分,并重新组合? – 2013-03-14 08:08:00
'如果[$ result> $ value]'不起作用。使用'-gt'代替'>'来比较“大于”。 '>'用于标准输出重定向;它会创建一个名为'$ value'的文件,并且'if'测试总是会成功。 – 2013-03-14 08:15:12
感谢Costi,我会放弃并回来。我之前试过-gt,因为我读的是它想要的,但它给了我一个错误,说它期望别的东西?抱歉不记得是什么,但我会给它一个去,并发布一些有用的东西回来即'嘿它现在有效',或'我不知道我在做什么,因为它说X'。真的很感谢帮助。 Richard – 2013-03-15 09:46:47