Today found a system to detect the integrity of the shell script, I tried it can be, introduced to everyone.
System: CentOS 5.x
Script content:
Copy Code code as follows:
Cat my_filecheck.sh
#!/bin/bash
#
# variable first declared to use
Shopt-s-O Nounset
# statement
# 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 storage file
Fp= "/root/fp. $Date. Chksum"
# What kind of checksum tool to use
Checker= "/usr/bin/md5sum"
Find= "/usr/bin/find"
# function Area #
Scan_file () {
Local F
For F in $Dirs
Todo
$Find $f-type F >> $TMP _file
Done
}
# Read the file to establish a checksum value for each file
Cr_checksum_list () {
Local F
If [f $TMP _file]; Then
For f in $ (cat $TMP _file);
Todo
$Checker $f >> $FP
Done
Fi
}
Rmtmp () {
[f $TMP _file] && rm-rf $TMP _file
}
# Main program Area
# Scan List
Scan_file
# Establish the checksum value of the file
Cr_checksum_list
# Clean up temporary files
Rmtmp
Execute script:
Copy Code code as follows:
To verify:
Copy Code code as follows:
Md5sum-c Fp.20141205160628.chksum
As follows:
Copy Code code as follows:
Md5sum-c Fp.20141209202544.chksum
/bin/gawk:ok
/bin/igawk:ok
/bin/ln:ok
/bin/loadkeys:ok
/bin/gzip:ok
/bin/mkdir:ok
/bin/date:ok
/bin/cat:ok
/bin/mountpoint:ok
/bin/taskset:ok
/bin/umount:ok
/bin/mount:ok
/bin/doexec:ok
/bin/kill:ok
/bin/sync:ok
/bin/unicode_start:ok
/bin/usleep:ok
/bin/mknod:ok
/bin/setserial:ok
/bin/cp:ok
/bin/mktemp:ok
/bin/setfont:ok
/bin/unicode_stop:ok
.....
/lib/modules/2.6.18-194.el5pae/kernel/crypto/cast5.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/crypto_blkcipher.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/twofish.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/authenc.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/cbc.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/crypto_hash.ko:ok
/lib/modules/2.6.18-194.el5pae/kernel/crypto/seqiv.ko:ok
/lib/libproc-3.2.7.so:ok
/lib/libacl.so.1.1.0:ok
/lib/libauparse.so.0.0.0:ok
/lib/libdmraid.so.1.0.0.rc13-17:ok
/lib/libvolume_id.so.0.66.0:ok
/lib/libgobject-2.0.so.0.1200.3:ok
/lib/libnss_compat-2.5.so:ok
/lib/rtkaio/i686/nosegneg/librtkaio-2.5.so:ok
/lib/rtkaio/librtkaio-2.5.so:ok
/lib/libdmraid-events-isw.so.1.0.0.rc13:ok
/lib/libdevmapper-event-lvm2snapshot.so.2.02:ok
/lib/libblkid.so.1.0:ok
/lib/libdb-4.3.so:ok
/lib/libsegfault.so:ok
/lib/libiw.so.28:ok
/lib/libdmraid-events-isw.so.1.0.0.rc13-17:ok
Can see a lot of OK.
If you only want to see the error, you can use the following command:
Copy Code code as follows:
Md5sum-c fp.20141209202544.chksum |grep-v "OK"
My system has no error, so there is no way to give you the results.