1

How to make a streaming (in one command or script) a task for:

  • compare the contents (files and folders) of the two directories dir1 and dir2
  • if new files appear in the dir1 directory, start copying them to dir2 and simultaneously process them with a handler:

diff -> copy -> exec some.sh

closed as too broad by jasonwryan, Stephen Rauch, Jeff Schaller, G-Man, mdpc Nov 22 '17 at 19:53

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0

List out the contents of dir1 to file1.txt using below command

ls -ltr | awk '{print $9}'  > /var/tmp/file1.txt

file1.txt contains this content

t1
1
l.sh
r.txt
l.py
l.txt
p.txt

List out the contents of dir2 to file2.txt using below command

ls -ltr | awk '{print $9}' > /var/tmp/file2.txt
t1
1
l.sh
r.txt
l.py
l.txt

Now this command will find the content which is not present in file2.txt when compared to file1.txt to copy to directory 2

awk 'NR==FNR {a[$1];next}!($1 in a) {print $1}' file2.txt file1.txt |
awk '{print "cp -rvfp" " " "directory1path”$1 " " "directory2path"}' |
sh
-2

You can do it by two methods:

  1. Using soft link

    Use this command to get a another copy of source in destination folder

    ln -s  source destination
    

    but in this case once source file or directory is deleted the link will be broken and you will not be able to access it.

  2. Using rsync

    rsync -avzh sourcepath destinationpath
    

    This command will automatically sync source and destination. Schedule a crontab for 1 minutes for this command so it continously checks and updates.

  • How does this achieve the part about running a handler program on the files? – ilkkachu Nov 22 '17 at 9:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.