How to write a bash script based on the modified of the files?

This is using SuSE Linux Enterprise 12.3. We are thinking of writing a bash script to find out the whether a group of files with *.rf were updated for the past 4 hours. We wanted to ensure that at least 1 or more of these *.rf files in /usr6/MAPS4/ folder. We are thinking of checking based on the "Modified date" of the file. If at least 1 *.rf file was updated for the past 4 hours, that means thing is working fine. Else, if none were updated, an alert will be triggered.

How to write this bash script? Please show with example.

Thanks in advance.
MichaelBalackSenior System EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
You still need to replace ALERT with your alerting code...

COUNTFILES=$( find /usr6/MAPS4/ -name '*.rf' -mmin 240 | wc -l )
if [ "$COUNTFILES" ne "0" ] ; then ALERT.... fi

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Likely noci's code will be best.

Another approach... If you have many files (1,000,000) or are trying to avoid any additional disk I/O on a busy system, use inotifywait.

inotifywait -mr --timefmt '%Y-%m-%d-%T' --format '%T %w%f %e' /var/log | while read time file event ; do

# code here to process data based on time + file + event
echo "$time $file $event"


Open in new window

MichaelBalackSenior System EngineerAuthor Commented:
Thanks for both experts, it works.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.