Get the App
SLTechnology News&Howtos  ›  Network Security  › 

SHELL system file integrity check

Shulou Source: shulou.com Published: 2022-06-01 07:14:49 11月25日 Update

System integrity audit tool

The shell script is as follows:

#! / bin/bash## variable can be declared before using shopt-s-o nounset# declaration # Establishment date Date=$ (date +'% Y% m% d% H% M% S') # directory added to the audit # Dirs= "/ bin/ sbin / usr/bin / usr/sbin / lib / usr/local/sbin / usr/local/bin / usr/local/lib" # temporary file # TMP _ file=$ (mktemp / tmp/check.XXXXXX) # File checksum storage file FP= "/ root/fp.$Date.chksum" # which checksum tool Checker= "/ usr/bin/md5sum" Find= "/ usr/bin/find" # function area # scan_file () {local f for fin $Dirs do $Find $f-type f > > $TMP_file done} # read Take the file to establish the checksum value cr _ checksum_list () {local f if [- f $TMP_file] for each 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 the checksum value cr _ checksum_list# of the creation file cr _ checksum_list# cleans up the temporary file rmTMP

Script execution:

[root@node3 ~] # sh my_filecheck.sh

To verify:

Md5sum-c fp.20141205160628.chksum

If all OK, the word OK will be displayed. If there is a problem, the corresponding error will be reported, as follows:

[root@node3 ~] # 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 8267 listed files could not be read

Tags: Files tools scripts integrity systems main programs functions variables words dates directories errors problems storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Redmi Huawei MySQL