有相当多的异常...
1)您正在使用您的grep的扩展正则表达式。所以你应该使用
-E option
。
2)在你的find命令,而不是引用的3210做
\;
3)既然你放置脚本在你的bin/bash的目录,确保路径添加到您的PATH环境变量。其他方法是提供脚本所在的整个路径。
4)您的if then else
循环中没有echo
语句。
5)在您的find命令中,您需要提供要查找文件的路径。使用.
作为当前目录。例如find . -type f -exec ./script.sh {} \;
我对脚本进行了以下更改(您可以添加自己的RegEx)。这是我得到的 -
[jaypal~/Temp]$ cat script.sh
#!/bin/bash
if grep -E '[a-zA-Z]*' ${1} >/dev/null
then
echo "!!! $1 is malware!!!"
else
echo " $1 is fine."
fi
输出:
[jaypal~/Temp]$ find . -type f -exec ./script.sh {} \;
./.mp3 is fine.
./1 is fine.
!!! ./a.sh is malware!!!
!!! ./ab.sed is malware!!!
!!! ./b.sh is malware!!!
!!! ./backup/GTP_Identifier.sh is malware!!!
!!! ./backup/GTP_Parser.sh is malware!!!
!!! ./backup/split.pl is malware!!!
!!! ./backup/T20111017153052.NEW is malware!!!
!!! ./backup/T20111025172411.NEW is malware!!!
!!! ./backup/T20111107193400.NEW is malware!!!
哦,我...第一行是不应该在脚本中去:) – sehe
大声笑,这是一个错字! – algorithmicCoder
尝试使用脚本的完整路径。例如:/home/xx/is-it-malware.sh – malletjo