System Integrity Audit Tool
The shell script is as follows:
The #!/bin/bash## variable is first declared to use shopt -s -o nounset# declaration # build Date date=$ (date + '%Y%m%d%H %m%s ') # join the approved directory #Dirs = "/bin /sbin /usr/bin /usr/sbin /lib /usr/local/sbin /usr/local/bin /usr/local/lib "# temp file #TMP_file =$ (mktemp /tmp/ Check. XXXXXX) # File checksum store file fp= "/root/fp. $Date. Chksum" # What kind of checksum tool checker= "/usr/bin/md5sum," find= "/usr /bin/find "# function area #scan_file () { local f for f in $Dirs do $Find $f - type f >> $TMP _file done}# Read the file to establish the checksum value for each file Cr_checksum_list () { local f if [ -f $TMP _file ]; then for f in $ ( cat $TMP _file); do $Checker $f >> $FP done fi}rmtmp () { [ -f $TMP _file ] && rm -rf $TMP _file}# Main program Area # scan list scan_file# Establish checksum value of the file cr_checksum_list# clean up temporary files rmtmp
Script execution:
[Email protected] ~]# sh my_filecheck.sh
To verify:
Md5sum-c Fp.20141205160628.chksum
If all OK, will show the word OK, if there is a problem, report the corresponding error, as follows:
[Email protected] ~]# Md5sum-c fp.20141205160628.chksum | Grep-v "OK" md5sum:/usr/bin/chattr:no such file or directory/usr/bin/chattr:failed Open or readmd5sum:warning:1 of 82 Listed files could not be read
This article is from the "Sword Slave" blog, be sure to keep this source http://diudiu.blog.51cto.com/6371183/1586734
SHELL System File Integrity check