Is My Two-Script File Management Approach Effective?

0
11
Asked By CuriousCoder42 On

Hey folks! I'm looking for some feedback on a file management script I created. The goal was to build a system that can copy, move, or delete files from certain folders based on configurations defined in a YAML file.

The process I came up with involves two scripts. The first reads the YAML configuration, which specifies the operation (like moving files), the source and destination folders, how often to perform the operation, and a name for that configuration.

For instance, let's say I have a configuration called 'Books' set to move '.epub' files from '/downloads' to '/ebooks' every 1440 minutes. The main script duplicates a base script, renaming it (like from base.sh to Libros.sh), uses 'sed' to replace placeholders with the values from the YAML file, and sets it up as a cron job.

I've tested it thoroughly, and it works great for my needs! But I'm curious if anyone thinks this two-script method is the right approach or if you have any alternate strategies in mind?

5 Answers

Answered By FileMaster99 On

Your method sounds neat, but you might want to be careful with the way you're substituting values, especially when shell characters could be involved. Since you're working on Debian, double-check how filenames might be processed. Using 'eval' in your script could lead to some unexpected results if the input isn't handled properly. Make sure your program can handle all kinds of filenames!

ScriptSavant88 -

Debian is good! When your second script runs, it generates commands like `cp /downloads/*.epub /ebooks`. I believe the 'cp' command should manage filenames correctly, but it's wise to test edge cases, just to be safe!

Answered By TechieTim On

Have you considered using rsync? It might handle your requirements better than the cp or sed commands you’re using.

CuriousCoder42 -

Good point! I thought using bash would make it simpler, but I’ll definitely look into rsync’s capabilities.

Answered By YAMLWizard On

How about just using one script that parses all your different YAML files? It could make your setup more efficient!

Answered By TemplateGuru77 On

Honestly, your approach isn’t how I would tackle this. It resembles a template engine, and while it might work, there could be hidden issues with the eval process you’re employing. Instead, I’d recommend using a well-known template tool like jinja2 or gomplate to generate your script. That would simplify your main script while ensuring that you don’t have to regenerate everything if you improve the template—or just set up the cron job to run `my_tidy_script books.yaml` directly instead. It can be cleaner and less error-prone!

CuriousCoder42 -

I've set up my control script to check for updates in the YAML file and regenerate the script as needed. I also use yq-go to read YAML values!

Answered By BackupBot123 On

I’d opt for a cron job that uses rsync instead of cp. It manages issues like existing files and spaces in names much more gracefully, plus it can handle logging, making troubleshooting easier.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.