How to use the MD5 value of the linux recording command
This article brings you how to use the MD5 value of the inux recording command. Most of the knowledge points are often used by everyone, so I will share them for you as a reference. Let's follow the editor and have a look.
1. Record the current command:
Sh CheckCommDDCW.sh
two。 Record new commands or modified commands (the keyword add can be replaced with any non-empty string):
Sh CheckCommDDCW.sh add
The code is as follows:
Git download: https://codeload.github.com/ddcw/shell/zip/master
#! / bin/env bash#write by ddcw# https://cloud.tencent.com/developer/column/6121#scriptname:CheckCommDDCW.shbegintime=`date +% s`file _ name=~/.UserCheckCom.txtnew_comm_n=0change_comm_n=0new_comm= "" change_comm= "[- f ${file_name}] | | touch ${file_name} for i in $(compgen-c) do if which $I > / dev/null 2 > & 1 then md5_n=$ (md5sum $(which $I) | awk '{print $1}') if cat ${file_name} | grep "\ # $I\ #" > / dev/null 2 > & 1 then # echo $(cat ${file_name} | grep "\ # $I\ #") md5_o=$ (cat ${file_name} | grep "\ # $I\ #" | tail-1 | awk'{print $NF}') if ["${md5_" N} "! =" ${md5_o} "] then # echo-e" COMMD [1 41 33m $I\ 033 [0m may be Changed: old_MD5: ${md5_o} new_MD5: ${md5_n} "[- z $1] | | echo-e" # ${I} #\ t $(date +% Y%m%d-%H:%M:%S)\ t ${md5_n} "> ${file_name} change_comm_n=$ [${change_comm_n}] + 1] change_comm= "${change_comm} ${I}" fi else if ["${I}"! ='['] then new_comm_n=$ [${new_comm_n} + 1] new_comm= "${new_comm} ${I}" # echo-e "\ 033 [32 40m$i\ 033 [0m "echo-e" # ${I} #\ t $(date +% Y%m%d-%H:%M:%S)\ t ${md5_n} "> ${file_name} fi doneecho"if [${new_comm_n}-gt 0] then echo-e"\ 033 [31 40m Total Add ${new_comm_n} commd\ 033 [0m "echo" ${new_comm} "else echo-e"\ 033 [32x 40m No Command Added, It's Seccurity!\ 033 [0m\ n "fiif [${change_comm_n}-gt 0] then echo-e"\ 033 [31ter40m Total Changed ${change_comm_n} commd\ 033 [0m "echo" ${change_comm} "else echo-e"\ 033 [32] 40m No Command Changed, It's Seccurity!\ 033 [0m "fiendtime= `date +% s`costm = `echo ${begintime} ${endtime} | awk'{print ($2liche 1) / 60} '`echo-e"\ n\ 033 [32th 40m `date +% Y%m%d-%H:%M:% S`cost ${costm} minutes\ 033 [0m "
The above is the use of the inux record command MD5 value, the code example is simple and straightforward, if you encounter this problem in your daily work. Through this article, I hope you can get something. For more details, please follow the industry information channel!