linux shell脚本实现/etc/passwd文件是否被更改

脚本实现

[root@rhel77 ~]# cat md5sum.sh 
#!/bin/bash

FILES="/etc/passwd"
while true
do
  echo "The Time is $(date +%F-%T)"
  OLD=$(md5sum $FILES | cut -d" " -f 1)
  sleep 5
  NEW=$(md5sum $FILES | cut -d" " -f 1)
  if [ $OLD != $NEW ];then
    echo "The $FILES has been modified."
    break
  else
    echo "The $FILES has not been modified."
  fi
done
[root@rhel77 ~]# 

其中,date参数:

%F:full date; same as %Y-%m-%d

%T:time; same as %H:%M:%S

你可能感兴趣的:(linux,shell,linux,shell)