This script runs in /config/ folder only with RSS ?

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
BiGs
Newbie
Newbie
Posts: 3
Joined: January 23rd, 2020, 6:17 pm

This script runs in /config/ folder only with RSS ?

Post by BiGs »

Hey. I tested and tuned this script and it works fine when manually adding it as a post script to an nzb from the main page manually. As soon as i applied it to an RSS feed, it ran in my /config/ folder and deleted all my config stuff, including my .ini and then moves what is remaining of my config folder to the mv directory. (the release it was meant to apply for remains in incomplete folder) It has now done this twice (after a sabnzbd reinstall), but the first time I had no idea what caused it because it ran manually ok. I'm not sure how to debug this as I don't want to reinstall sabnzbd every time it does this. I'm not using a category folder with the RSS or the manual adding as it has the mv function in the script. So it can't be a destination conflict? Works great manually. So I'm seeing if someone with more bash/sabnzbd experience then me could see what is happening here.

The script basically cleans up any junk usenet files and removes a serial number that gets placed on the end of every nzb on an indexer I use. The serial number always starts with a _[#number] but sometimes doesn't have the "_" so I made a "_" or a "[" as the post removal trigger as no nzbs i download from this site has those characters. It did the job great when manually testing nzbs from main page. They get moved to that directory with the serial tag removed and release intact. As soon as I then run it in a rss post script, my sabnzbd implodes. The last 3 lines of code is the only thing new with this script then the others I run. The conflict with sabnzbd must be in that part of the script. (but it is deleting files from config too, which means the find statement is being applied to config too.) I'm really stumped by this.

I run the 'linuxserver' docker version of sabnzbd out of an unraid server. (forum wouldn't let me link the docker page)

Thanks for any help.

Code: Select all

#!/bin/bash

cd ~ && cd $1

find . -type f | grep -v '.r\|.mkv\|.jpg\|.nfo\|.sfv' | xargs rm

relpath=$(pwd)
relname=`basename "$relpath" | cut -f1 -d"_" | cut -f1 -d"["`

mv $relpath `echo /mnt/user/Main.Share/NZB/$relname`
User avatar
safihre
Administrator
Administrator
Posts: 5338
Joined: April 30th, 2015, 7:35 am
Contact:

Re: This script runs in /config/ folder only with RSS ?

Post by safihre »

That's strange!
So how did you setup the script for your RSS feed, via Config > RSS and then selected the script there?
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: This script runs in /config/ folder only with RSS ?

Post by OneCD »

BiGs wrote: February 9th, 2020, 9:14 pm

Code: Select all

cd ~ && cd $1
You need to be careful with this line.

The tilde ~ usually means $HOME for the current user (but not always). If you're running SABnzbd as a different user then running this script, be aware $HOME will be a different location. I've no idea what environment variables look like inside docker installations, but it's something to consider.

Are you passing a path to this script? The $1 suggests you're providing a path for it to operate in.

Until you work out exactly where the script is running, strongly suggest disabling the 'rm' command. ;)
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
BiGs
Newbie
Newbie
Posts: 3
Joined: January 23rd, 2020, 6:17 pm

Re: This script runs in /config/ folder only with RSS ?

Post by BiGs »

safihre wrote: February 10th, 2020, 1:58 am That's strange!
So how did you setup the script for your RSS feed, via Config > RSS and then selected the script there?
Correct. The top line of drop down box for post script on the feed page. the accept "*" line after all the rejects i leave on default which reverts to the top master setting. I selected the same script as I did manually adding via the main page add form with the post script. No changes had been made to the script between. I ran the script maybe 20 times prior to adding it to the RSS feed, including a whole TV season.
OneCD wrote: February 10th, 2020, 2:36 am
BiGs wrote: February 9th, 2020, 9:14 pm

Code: Select all

cd ~ && cd $1
You need to be careful with this line.

The tilde ~ usually means $HOME for the current user (but not always). If you're running SABnzbd as a different user then running this script, be aware $HOME will be a different location. I've no idea what environment variables look like inside docker installations, but it's something to consider.

Are you passing a path to this script? The $1 suggests you're providing a path for it to operate in.

Until you work out exactly where the script is running, strongly suggest disabling the 'rm' command. ;)
To be honest I butcher up lines i find on google and test and tune until i get it to do what I want. That was in the very first script I put together. I'm not even sure what it does (root/home directory and setting to a variable i think?), but it has been in all of my sabnzbd scripts straight after the #!/bin/bash so I didn't think much of this being the cause. I never call the $1 so maybe this line isn't even needed in any of my scripts? I've been running that find xargs rm line in all my clean up scripts without issues (including my mp3 script which runs like 300 times a day via RSS flawlessly). Should I maybe change it to echo the files that it finds instead maybe? to troubleshoot it? Instead of rm. What would you suggest?

Thanks for the help.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: This script runs in /config/ folder only with RSS ?

Post by OneCD »

BiGs wrote: February 10th, 2020, 3:22 am

Code: Select all

cd ~ && cd $1
I'm not even sure what it does (root/home directory and setting to a variable i think?),
It means "change directory to current user's home. If this was successful, then change directory again to the first argument passed to this script."
It's a method of ensuring you know which directory your script will continue to operate in, and suggests you'll be using relative paths from here on (as per your 'find' command). But, as shown in my previous post, this can change depending on the user running this script.

So, it may not be required at all for your purposes. ;)

Maybe consider hardcoding the full target path instead? Instead of using relative paths?
BiGs wrote: February 10th, 2020, 3:22 am To be honest I butcher up lines i find on google and test and tune until i get it to do what I want.
The only way you'll write your script correctly is to learn shell-scripting. Shel-scripting is not really something you can copy/paste. You have to learn how to modify each command to suit your specific need.
BiGs wrote: February 10th, 2020, 3:22 am Should I maybe change it to echo the files that it finds instead maybe? to troubleshoot it? Instead of rm. What would you suggest?
That's a good idea. Certainly disable 'rm' or else you'll keep losing files you'd rather keep. ;D

Start by disabling the pipe to 'xargs':

Code: Select all

find . -type f | grep -v '.r\|.mkv\|.jpg\|.nfo\|.sfv' #| xargs rm
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
BiGs
Newbie
Newbie
Posts: 3
Joined: January 23rd, 2020, 6:17 pm

Re: This script runs in /config/ folder only with RSS ?

Post by BiGs »

Thanks for the help, OneCD. I will try these things and troubleshoot.

Yeah I tried to do some online tutorials. I got the basics doing this way but I got lost beyond that. I'm a tradesman and I have always learnt just by doing. I start to understand copy pasted lines and how they react. I know it's a bit half arsed but it seems to be working for my purposes. :)

I reinstalled. The download in question was solely sitting in my history with the script log (logs moved with /config/). I don't remember that last time but I may have missed it.

Code: Select all

/mnt/user/Main.Share/NZB/scripts/WTFBRTV_RENAME[.]sh: line 3: cd: too many arguments
mv: cannot remove '/config/admin': Directory not empty
mv: cannot remove '/config/logs': Directory not empty

So maybe that $1 line could be the problem and can be removed in the sabnzbd environment. It must be conflicting with the basename/pwd lines as that cd $1 line is in all my scripts and I run them all in the same way. Sabnzb must treat RSS scripts in a slightly different way or privilege or directory structure though for this to only occur via RSS. I'll have a poke around and # that xargs rm. Cheers.
Post Reply