我有一臺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