BASH - how do i detect the file date time is changed so do a copy or move now once its done?

StackOverflow https://stackoverflow.com/questions/20100133

  •  03-08-2022
  •  | 
  •  

Question

I have a static directory: /var/tmp/files

This directory is only shared with users for upload/download via SFTP, it has some static file names such as:

recording-security.frontdoor.avi
recording-security.backdoor.avi
recording-security.parkingspace.avi
....

from another PC via SFTP those files are getting removed/edited/updated/added etc Now another path: /var/www/html/livevideo-stream/

those files are copied, moved from /var/tmp/files

How can i using BASH read those files were edited or newly added or overwritten? So, that my script can move valid contents from /var/tmp/files to livevide-stream only those which has been modified or newly added etc?

$ crontab i have:
0 7 * * * /var/tmp/finishit.sh
0 8 * * * /var/tmp/finishit.sh
0 9 * * * /var/tmp/finishit.sh
0 19 * * * /var/tmp/finishit.sh
0 20 * * * /var/tmp/finishit.sh

$ cat /var/tmp/finishit.sh

#!/bin/bash
cd /var/tmp/files
while :
do

  """
  how do we now validate those files which was modified or changed or newly added and place them in that directory?
  """
  # echo $1 $2
  cp -R /var/tmp/files/* /var/www/html/livevideo-stream/
  sleep 1

done
Was it helpful?

Solution

Your cron will launch your script several times per hour, and your script does not terminate due to the while : loop... You will end up with a lot of background scripts trying to copy stuff ever second.

You should simply replace the whole script with

rsync -vaq /var/tmp/files/* /var/www/html/livevideo-stream/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top