Help with script

  • So I wasn't sure exactly where to put this on the forums, but this section seemed right. My apologies in advance if this is the wrong location, sorry.


    So I'm trying to setup a script that runs after transmission finishes that renames some files and changes ownership and permissions of recently downloaded and moved files. Below is my code with what I have working and some commented out that I'm trying to make work in the right way. Sadly my bash script coding isn't neat or very clean. I was hoping there might be a gentlemen or lady (or more) that could help me get it to be simpler and be quicker (maybe using some sort of loop ) and work better instead of grabbing all files. Currently this lags the bejesus of my machine for a couple minutes every time it runs. I appreciate and thank for any advice or help.



    P.S. I'm using transmission to download and Sickbeard/Couchpotato to organize and move everything.

    Modpic.gif

    Dell Precision T3500
    Processor:
    Intel Core i7 960 @3.2ghz
    Memory:
    26GB RAM
    Kernel: Linux 5.10.0-0.bpo.9-amd64
    Version: 5.6.2-1 (Usul) Debian Buster [From Fresh Install of 5]

    Einmal editiert, zuletzt von Solo0815 ()

  • You can use sed with a textfile that executes all of your replacements in one run.


    I'm not at my pc right now so I have to post an example later...


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • You can use sed with a textfile that executes all of your replacements in one run.


    I'm not at my pc right now so I have to post an example later...


    Greetings
    David



    Thanks Dave. I've been fiddling with the script for a while now and I eventually gave up and just used that there for a bit, but only run it manually at night when nothing else is going lol. :(. Thanks again, you're always so helpful!

    Modpic.gif

    Dell Precision T3500
    Processor:
    Intel Core i7 960 @3.2ghz
    Memory:
    26GB RAM
    Kernel: Linux 5.10.0-0.bpo.9-amd64
    Version: 5.6.2-1 (Usul) Debian Buster [From Fresh Install of 5]

  • Script:


    Bash
    #!/bin/bash
    
    
    #Variables declaration
    downloadsPath="/media/96e60511-62ca-48ba-bccc-9b365bfcc4e5/downloads/"
    sedPattern="/etc/default/sedpattern"
    
    
    cd "${downloadsPath}"
    find . -type f | sed -f "${sedPattern}"  >>name.log 2>&1


    Content of sedPattern can be filled with what you have already


    Code
    s|:|-|g
    s/\[.*?\] //
    ...


    The rest should be a piece of cake for you.


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!


  • Thanks again Dave, so I take it that the chmod/chown is in the most simplified setup?

    Modpic.gif

    Dell Precision T3500
    Processor:
    Intel Core i7 960 @3.2ghz
    Memory:
    26GB RAM
    Kernel: Linux 5.10.0-0.bpo.9-amd64
    Version: 5.6.2-1 (Usul) Debian Buster [From Fresh Install of 5]

  • I havent put the chown/chmod in, thought you could pull that off yourself. ;)


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • I havent put the chown/chmod in, thought you could pull that off yourself. ;)


    Greetings
    David


    Hey so I setup the script, and I didn't realize until I running it, but all that does is list what the files would look like if filtered with the sed parameters. Nothing is renamed...


    Log file output:

    Code
    ./Cross Ange- 113 [480p].mkv
    ./Cross Ange- 113 [720p].mkv


    But nothing happens to the files :(

    Modpic.gif

    Dell Precision T3500
    Processor:
    Intel Core i7 960 @3.2ghz
    Memory:
    26GB RAM
    Kernel: Linux 5.10.0-0.bpo.9-amd64
    Version: 5.6.2-1 (Usul) Debian Buster [From Fresh Install of 5]

  • Oups... I use my script differently thats why it worked for me...


    Everything I find suggests to use rename instead of sed but I don't find someone that does a massive rename like you do.


    Can you show an example of a file how it looks before and after? And why don't Sab/Sick already name it right?


    PS: My renamer scripts for Sab: https://github.com/davidh2k/postprocessingscripts (comments on filme/movies are in german)


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • try this (untested):


    please make a backup of you files to another folder before trying this!


  • Well I use flexget to automate the downloading of anime for me and sickbeard doesn't recognize the file names because they're unconventional and IMO idiotically done by subbing groups. They used to have way better naming conventions years ago (also use 8bit and make smaller files for download, but that's ages back). So I use the script to strip out parts of the files based on a few criteria. I start by always looking for colons and bracketed areas first; then I add in replacement stuff based on the anime title and normal subing groups to remove certain aspects of the show that I find in the file names. I have to continually change the variable parts based on the current season of anime with the shows I'm downloading, but only have to do that every few months and isn't a problem because of my template I created.


    Here's 2 example file names:
    [HorribleSubs] Cross Ange - 13 [720p].mkv -> Cross Ange- 113.mkv
    [DeadFish] Madan no Ou to Vanadis: Tigre-kun to Vanadi-chu - 08 - ONA [720p][AAC].mp4 -> Madan no Ou to Vanadis- 108.mp4


    @Solo0815


    Code
    cd "${downloadsPath}"
    for FILENAME in *.*; do 
      NEWFILENAME="$(echo "$FILENAME" | sed -f "${rename}")"
      mv -v "$FILENAME" "$NEWFILENAME" >>name.log 2>&1
      echo renamed
    done


    It works great, thanks Solo! Just made everything way quicker and easier to add/remove renaming parts I don't need when shows stop.

    Modpic.gif

    Dell Precision T3500
    Processor:
    Intel Core i7 960 @3.2ghz
    Memory:
    26GB RAM
    Kernel: Linux 5.10.0-0.bpo.9-amd64
    Version: 5.6.2-1 (Usul) Debian Buster [From Fresh Install of 5]

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!