Avatar of MichaelBalack
MichaelBalack
Flag for Singapore asked on

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.
LinuxScripting Languages

Avatar of undefined
Last Comment
MichaelBalack

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
noci

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
David Favor

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"

done

Open in new window

MichaelBalack

ASKER
Thanks for both experts, it works.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23