您好,登錄后才能下訂單哦!
這篇文章為大家?guī)韎nux記錄命令md5值的使用方法。大部分知識點都是大家經(jīng)常用到的,為此分享給大家做個參考。一起跟隨小編過來看看吧。
1.記錄當(dāng)前命令:sh CheckCommDDCW.sh
2.記錄新增命令或被修改命令(關(guān)鍵詞add可以替換為任意非空字符串):sh CheckCommDDCW.sh add
git下載:https://codeload.github.com/ddcw/shell/zip/master
#!/bin/env bash
#write by ddcw
#https://cloud.tencent.com/developer/column/6121
#scriptname:CheckCommDDCW.sh
begintime=`date +%s`
file_name=~/.UserCheckCom.txt
new_comm_n=0
change_comm_n=0
new_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 \033[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
fi
fi
done
echo ""
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[32;40m No Command Added ,It's Seccurity!\033[0m\n"
fi
if [ ${change_comm_n} -gt 0 ]
then
echo -e "\033[31;40m 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"
fi
endtime=`date +%s`
costm=`echo ${begintime} ${endtime} | awk '{print ($2-$1)/60}'`
echo -e "\n\033[32;40m `date +%Y%m%d-%H:%M:%S` cost ${costm} minutes\033[0m"
以上就是inux記錄命令md5值的使用方法,代碼示例簡單明了,如果在日常工作遇到此問題。通過這篇文章,希望你能有所收獲,更多詳情敬請關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。