
我有一個 crontab 條目,它執行腳本並將輸出儲存在檔案中,例如 currenthash.log 作為 MD5 哈希值。
但我無法實現這樣的要求:如果 MD5 校驗和發生變化,我需要建立一個新文件,例如changehash.log。這是我可以在 cronjob 或腳本本身中執行的操作嗎?
答案1
答案2
您需要將舊雜湊保存在某處,然後將其與新雜湊進行比較。這個方向的東西:
#!/bin/sh
file=/path/to/file
hashfile=/path/to/stored/hash
newhash=$(md5sum "$file")
oldhash=$(cat "$hashfile")
if [ "$newhash" != "$oldhash" ]; then
echo it changed...
fi
echo "$newhash" > "$hashfile"