0

I've never used entr before, but I intend to write a command in /etc/rc.local to copy the contents of a folder into another folder, every time a change is made inside the original folder.

For this example I have created two folders, one is 'test1' which will have the file in it, the other is 'test2' which will have folders generated named with the current time and these will contain the changes to the contents of test1 at the time. My attempt is as follows, but it doesn't work and gets the error "bash: '/home/Rob/Desktop/test1/2': No such file or directory entr: exec mkdir:: No such file or directory"

$ ls -d ~/Desktop/test1/* | entr $(mkdir ~/Desktop/test2/name_$(date '+%Y_%m_%d_%H_%M') ; $(cp ~/Desktop/test1/* ~/Desktop/test2/name_$(date '+%Y_%m_%d_%H_%M')))

The above will work only when I past into the terminal, not after I leave it running and make changes inside test1.

Note: I'll probably use rsync when I get this working, rather than cp.

Thanks.

4
  • I don't really know what entr is, but I do know that neither cp nor mkdir outputs anything, so putting them in command substitutions ($(...)) makes little sense. See also Why *not* parse `ls` (and what to do instead)?
    – Kusalananda
    Commented Oct 1, 2023 at 13:36
  • @Kusalananda, you're right about not needing to be a command substitution. I didn't understand that evaluated the output as string. I've made progress, but the issue is still that I want to enter one <command> into entr, but the only way I can figure out how to do that is to run a script as the <command>.
    – 1toneboy
    Commented Oct 2, 2023 at 5:12
  • The best way I can get it to work is: RUN- while true; do ls -d ~/Desktop/test1/* | entr -d bash ~/Desktop/script.sh done WHERE script.sh is- date=$(date '+%Y_%m_%d_%H_%M') mkdir -p ~/Desktop/test2/$date && rsync -aAXv ~/Desktop/test1/* ~/Desktop/test2/$date
    – 1toneboy
    Commented Oct 2, 2023 at 5:13
  • If your system supports inotify that might be a better way of triggering a task that would kick off a copy of your files.
    – user103944
    Commented Oct 2, 2023 at 14:41

0

You must log in to answer this question.

Browse other questions tagged .