监测linux一些重要文件md5值脚本

今天写了个小小的监测linux重要文件md5值的脚本,
为了安全最好在安装好系统之后部署

其实网上有开源软件 监测文件是否被修改


#!/bin/bash
#crontab everyday
FILENAME=`hostname`_MD5_`date +%Y%m%d%H%M`.txt
FILETEMP=`hostname`_MD5_`date -d yesterday  +%Y%m%d%H%M`.txt
logpath=/data/`date +%Y%m%d`
if [ ! -d $logpath ]; then
   mkdir $logpath
   chmod ugo+w $logpath
fi
cd $logpath


find /bin -type f |sort |xargs md5sum >$FILENAME.bin
find /sbin -type f |sort |xargs md5sum >$FILENAME.sbin
find /usr/bin -type f |sort |xargs md5sum >$FILENAME.ubin
find /usr/sbin -type f |sort |xargs md5sum >$FILENAME.usbin
find /etc -type f |sort |xargs md5sum >$FILENAME.etc

####
md5sum  -c $FILETEMP.bin  |grep -v OK >>$FILENAME
md5sum  -c $FILETEMP.sbin |grep -v OK >>$FILENAME
md5sum  -c $FILETEMP.ubin |grep -v OK >>$FILENAME
md5sum  -c $FILETEMP.usbin|grep -v OK >>$FILENAME
md5sum  -c $FILETEMP.etc  |grep -v OK >>$FILENAME

cd ..
find . -mtime +7 -name '*_MD5_*' -exec rm -f {} \;

=============================
原文地址:https://www.cnblogs.com/4admin2root/p/2931902.html