Cronjob to detect recently modified files

I want to run cronjob every minute to find all files that were changed at the last minute in a specific directory (about 300,000 inodes) and export this list of files to csv.

Is it possible to run an optimized command for this? I cannot run “find” with the sort flag in this directory because it is huge and it will probably take more than 1 minute to run all the files.

Is there any command I can do? Or run some special program on the background of the server, which registers each changed file as it changes? If there is a command using PHP for this, I'm fine, I can create a cron to execute a PHP script, no problem.

+5
source share
1 answer

There is a Linux utility called incron, which can be used similarly to normal cron, but instead of being time-based, they are disconnected from inotify and dismissed from file events.

Information on the Ubuntu page can be found here: http://manpages.ubuntu.com/manpages/intrepid/man5/incrontab.5.html

I personally did not have to use it for something too complicated, but it is something like this:

Install it:

sudo apt-get install incron 

Open the editor to add an entry:

 incrontab -e 

Put something like this:

 /var/www/myfolder IN_MODIFY curl https://www.example.com/api/file-updated/$# 

The first part is a file or folder to view. The second part is an event. And the third part is the team.

I think $# is a placeholder for this file.

+2
source

Source: https://habr.com/ru/post/1239458/


All Articles