We help IT Professionals succeed at work.

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

89 Views
Last Modified: 2019-02-20
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.
Comment
Watch Question

Software Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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

MichaelBalackSenior System Engineer

Author

Commented:
Thanks for both experts, it works.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions