shell脚本练习

2021/5/6 7:26:09

本文主要是介绍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脚本练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程