我用:
md5sum * > checklist.chk # Generates a list of checksums and files.
并使用:
md5sum -c checklist.chk # runs through the list to check them
如何自动化PASS或FAIL状态?我基本上想要通知我的应用程序上的某些内容发生了变化。无论是黑客还是开发人员未经授权的更改。我想编写一个脚本,通知我代码的任何更改。
我在网上发现了一些脚本,但它们似乎只适用于单个文件,我无法使脚本适用于具有通过或失败状态的多个文件。
if [ "$(md5sum < File.name)" = "24f4ce42e0bc39ddf7b7e879a -" ]
then
echo Pass
else
echo Fail
fi
参考:
Shell scripts and the md5/md5sum command: need to decide when to use which one https://unix.stackexchange.com/questions/290240/md5sum-check-no-file
答案 0 :(得分:0)
我会做类似的事情:
var array1 = ["ddd","aaa","eee","aaa","fff","bbb","ggg","aaa","ccc","fff"];
console.log(array1.sort());
答案 1 :(得分:0)
将校验和直接存储在脚本中。然后运行md5sum -c
。
类似的东西:
#!/bin/bash
get_stored_checksums() {
grep -P '^[0-9a-f]{32} .' <<-'EOF'
#########################################################
# Stored checksums in the script itself
# the output from the md5sum for the files you want guard
5e3f61b243679426d7f74c22b863438b Workbook1.xls
777a161c82fe0c810e00560411fb076e Workbook1.xlsx
# empty lines and comments - theyre simply ignored
d41d8cd98f00b204e9800998ecf8427e abc def.xxx
# this very important file
809f911bcde79d6d0f6dc8801d367bb5 jj.xxx
#########################################################
EOF
}
#MAIN
cd /where/the/files/are
#run the md5sum in the check-mode
result=$( md5sum -c <(get_stored_checksums) )
if (( $? ))
then
#found some problems
echo "$result"
#mail -s "PROBLEM" security.manager@example.com <<<"$result"
#else
# echo "all OK"
fi
如果出现问题,你会看到类似的内容:
Workbook1.xls: OK
Workbook1.xlsx: OK
abc def.xxx: FAILED
jj.xxx: OK
md5sum: WARNING: 1 of 4 computed checksums did NOT match
当然,您可以将get_stored_checksums
功能更改为其他功能,例如:
get_stored_checksums() {
curl -s 'http://integrityserver.example.com/mytoken'
}
您将从远程服务器获取受保护的校验和...