shell脚本练习


#!/bin/bash
#author:1209233066@qq.com
#function:md5检测文件内容变动
source /etc/init.d/functions
timestamp=$(date +%F)

finger(){
  file=(
    /etc/passwd 
    /etc/shadow
    /etc/sudoers
    /etc/rc.local
    /etc/rc.d/rc.local
    $(ls /var/spool/cron/*)
  )
  if [ -f "md5_${timestamp}" ];then
    rm -f md5_${timestamp}
  fi
  for i in "${file[@]}";do md5sum $i >>md5_${timestamp} ;done
}

check_finger(){
  md5sum -c md5_${timestamp} &>/dev/null
  if [ $? -eq 0 ];then
    action "文件没用改动" /bin/true
  else
    action "" /bin/false
  fi
}

declare -A main
main[‘finger‘]=finger
main[‘check‘]=check_finger

${main[$1]}

shell脚本练习

上一篇:linux下 QtCreator 运行不显示 qDebug 输出的问题


下一篇:更新Linux下openssl路径和库路径