Check a files Modified date and email if it has changed [closed]

元气小坏坏 提交于 2019-12-03 01:28:23

How about this?

#!/bin/bash

[[ -z `find /home/spatel/ -mmin -60` ]]

if [ $? -eq 0 ]
then
    echo -e "nothing has changed"
else
    mail -s "file has been changed" spatel@example.com
fi

Put this script in hourly cron job

01 * * * * /path/to/myscript 

linux supports the inotify command. You use it to monitor file activity - file change, file creation whatever you want, whenever you want.

The find command given above will not work on out-of-the-box solaris. It is fine for linux. You have two options on Solaris:

  1. go to www.sunfreeware.com and download gnu coreutils, which will install gnu find (the above version of find) in /usr/local/bin

  2. write a script that uses the touch command, wait more than 60 minutes then test the file, the only problem is this script runs in the background forever, you can avoid this if you know some perl to generate a timestring suitable for touch -t [time string] to create the file with a time one hour in the past This is the run forever version:

    while true

    do
       touch dummy
    
       sleep 3615 # 1 hour 15 seconds
    

    [ file_i_want_to_test -nt dummy ] && echo 'file blah changed' | mailx -s 'file changed' me@myco.com

    done
    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!