I'm looking for feedback on a dual-script solution I created for managing file operations. My approach involves a main script that reads configurations from a YAML file to copy, move, or delete files in designated folders. The configuration specifies the operation type, source and destination directories, and the interval between operations. For example, a configuration named 'Books' moves all .epub files from /downloads to /ebooks every 1440 minutes. The main script copies a base script, modifies it using sed to insert the configuration values, and schedules it with cron. I'm curious if this two-script method is a solid approach or if others would suggest different strategies. Any thoughts?
5 Answers
Your script sounds interesting, but I'd suggest being cautious with how you're handling the substitutions. Depending on the OS, like a Unix-based system, filenames can contain a wide range of ASCII characters. So just make sure that your script properly handles all possible filenames without breaking!
I'd also recommend replacing your current method with a single cron job that runs an rsync command rather than using cp. Rsync logs issues, handles errors gracefully, and can even remove files from the source after transferring, which could simplify your workflow.
What if you used one shell script that accepts different YAML files as input? It could parse the YAML and perform operations accordingly, simplifying your structure.
I see where you're going, but your strategy isn't quite what I would have chosen. You've created a sort of template engine, which could lead to issues when evaluating user input. I recommend using a reliable template engine like jinja2 instead. It would streamline your script generation and simplify the cron setup! An alternative would be to just run a command like `my_tidy_script books.yaml` directly as a cron job, which might prevent redundancy if you need to update the template later.
Interesting point! I actually have a control script that detects changes in the YAML file and regenerates the script if needed!
Have you considered using rsync? It might be a better alternative, given that it handles many edge cases automatically, like file existence and spaces in filenames, without having to stop for errors.
Great suggestion! I initially thought bash would be simpler, but I'll definitely look into rsync options.

Thanks for the heads up! I'm using Debian 13 and the command gets evaluated with `eval`, like `cp /downloads/*.epub /ebooks`. Do you think using `cp` will manage filenames correctly?