[Linux] Cleanup-script (Bash)

Come up with a useful post-processing script? Share it here!
Post Reply
jocke
Newbie
Newbie
Posts: 38
Joined: April 22nd, 2009, 4:47 pm

[Linux] Cleanup-script (Bash)

Post by jocke »

I've used SABnzbd on Windows for a while, and I've used a cleanup-script on most of my downloads, to remove files like .nfo, .srr, etc. I used a modified version of the script found here.

Now I'm moving to Linux, and I didn't find any cleanup-scripts for it, so I made one, and thought I'd share it. Nothing fancy, but quite handy.

cleanup.sh

Code: Select all

#!/bin/sh

filecount=0
nzbcount=0
sfvcount=0
nfocount=0
subcount=0
idxcount=0
srrcount=0

echo "This cleanup is intended for TV-shows."
echo ""
echo "Cleaning up download directory: $1"
echo ""

echo "Deleting .nzb-files"
nzbcount=`find $1 -type f -name "*.nzb" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .sfv-files"
sfvcount=`find $1 -type f -name "*.sfv" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .nfo-files"
nfocount=`find $1 -type f -name "*.nfo" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting subtitle-files"
subcount=`find $1 -type f -name "*.sub" -exec bash -c "rm -vf '{}'" \; | wc -l`
subcount=$[$subcount+`find $1 -type f -name "*.srt" -exec bash -c "rm -vf '{}'" \; | wc -l`]		

echo "Deleting .idx-files"
idxcount=`find $1 -type f -name "*.idx" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .srr-files"
srrcount=`find $1 -type f -name "*.srr" -exec bash -c "rm -vf '{}'" \; | wc -l`

let filecount=$nzbcount+$sfvcount+$nfocount+$subcount+$idxcount+$srrcount

echo ""
echo "Cleanup completed."
echo "Deleted $filecount files ($nzbcount .nzb, $sfvcount .sfv, $nfocount .nfo, $subcount subtitle-files, $idxcount .idx, $srrcount .srr)."
Last edited by jocke on January 21st, 2011, 11:14 pm, edited 1 time in total.
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Linux] Cleanup-script

Post by J03 8LACK »

Hey Jockie,

Your Script is great for cleaning unwanted files. I've been looking for a little help with a cleanup script. problem examples below


Movie Name/cover/*.jpg
Movie Name/CD1/*cd1.avi
Movie Name/CD2/*cd2.avi

or

Movie Name/Movie/*.avi

I want

Movie Name/*.avi

I have to manually move the avi around and delete folders. A script would be great

Any info would be great

J03
binhex
Sr. Member
Sr. Member
Posts: 470
Joined: December 5th, 2008, 11:54 am

Re: [Linux] Cleanup-script

Post by binhex »

J03 8LACK wrote: Hey Jockie,

Your Script is great for cleaning unwanted files. I've been looking for a little help with a cleanup script. problem examples below


Movie Name/cover/*.jpg
Movie Name/CD1/*cd1.avi
Movie Name/CD2/*cd2.avi

or

Movie Name/Movie/*.avi

I want

Movie Name/*.avi

I have to manually move the avi around and delete folders. A script would be great

Any info would be great

J03
hi joe, i see your still looking into a post processing script to tidy things up, as i mentioned i have such a script which does the above (plus quite a bit more), here is the link to the source code, take a look over it it might help:-

http://www.mediafire.com/?8dada7x99mmmwj1

just to detail what this script does:-

deletes files smaller than certain size
copies movie files based on file type e.g. avi, mkv, mp4
deletes unwanted subfolders, think you might like this one joe  ;D
copies metadata to movie destination
copies coverart to movie destination
deletes nzb file from nzb folder (normally archived nzb.gz files)
deletes sd movie if hd movie downloaded
marks movie with _encode_ if movie over certain size (useful if you want to shrink)

if this script becomes popular i may put some more effort in and tidy it up, as it is its fiarly rough and ready but does do the job.

enjoy.

binhex.
J03 8LACK
Full Member
Full Member
Posts: 120
Joined: April 2nd, 2009, 1:33 am

Re: [Linux] Cleanup-script

Post by J03 8LACK »

Binhex

Thanks I will Take a Look


J03
bcos
Newbie
Newbie
Posts: 1
Joined: August 7th, 2010, 11:47 am

Re: [Linux] Cleanup-script

Post by bcos »

Thanks for sharing this script! I've been meaning to find a post-processing script to do just this. However, the script says it is unable to find the right directory. Here is an example error:
Cleaning up download directory: /media/Movies/Movies/Movie Title (2010)

Deleting .nzb-files
find: `/media/Movies/Movies/Movie': No such file or directory
find: `Title': No such file or directory
find: `(2010)': No such file or directory
It seems that spaces in the directory names aren't appreciated. Any work around for this issue (that doesn't involve removing the spaces)?

Thanks
Last edited by bcos on August 7th, 2010, 4:18 pm, edited 1 time in total.
WBFT
Newbie
Newbie
Posts: 1
Joined: September 1st, 2010, 4:46 am

Re: [Linux] Cleanup-script

Post by WBFT »

Great script, but it doesn't work with spaces in directories. This is a problem for me.

Code: Select all

Rescue Me - 6x10 - A.D.D

This cleanup is intended for TV-shows.

Cleaning up download directory: /volume1/video/TV-Shows/Rescue Me/Season 6

Deleting .nzb-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
Deleting .sfv-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
Deleting .nfo-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
Deleting subtitle-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
Deleting .idx-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
Deleting .srr-files
find: /volume1/video/TV-Shows/Rescue: No such file or directory
find: Me/Season: No such file or directory
find: 6: No such file or directory
/var/packages/sab2/scripts/cleanup: let: line 46: expression expected

Cleanup completed.
Deleted 0+0+0+$[0+0]+0+0 files (0 .nzb, 0 .sfv, 
0 .nfo, $[0+0] subtitle-files, 0 .idx, 0 
.srr).
Someone with a solution??
jocke
Newbie
Newbie
Posts: 38
Joined: April 22nd, 2009, 4:47 pm

Re: [Linux] Cleanup-script

Post by jocke »

I'm not using this post-script anymore, but the following modified script should work just fine even if the folder/filename contain spaces;

Code: Select all

#!/bin/sh

filecount=0
nzbcount=0
sfvcount=0
nfocount=0
subcount=0
idxcount=0
srrcount=0

echo "This cleanup is intended for TV-shows."
echo ""
echo "Cleaning up download directory: $1"
echo ""

echo "Deleting .nzb-files"
nzbcount=`find $1 -type f -name "*.nzb" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .sfv-files"
sfvcount=`find $1 -type f -name "*.sfv" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .nfo-files"
nfocount=`find $1 -type f -name "*.nfo" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting subtitle-files"
subcount=`find $1 -type f -name "*.sub" -exec bash -c "rm -vf '{}'" \; | wc -l`
subcount=$[$subcount+`find $1 -type f -name "*.srt" -exec bash -c "rm -vf '{}'" \; | wc -l`]		

echo "Deleting .idx-files"
idxcount=`find $1 -type f -name "*.idx" -exec bash -c "rm -vf '{}'" \; | wc -l`

echo "Deleting .srr-files"
srrcount=`find $1 -type f -name "*.srr" -exec bash -c "rm -vf '{}'" \; | wc -l`

let filecount=$nzbcount+$sfvcount+$nfocount+$subcount+$idxcount+$srrcount

echo ""
echo "Cleanup completed."
echo "Deleted $filecount files ($nzbcount .nzb, $sfvcount .sfv, $nfocount .nfo, $subcount subtitle-files, $idxcount .idx, $srrcount .srr)."
User avatar
Mar2zz
Jr. Member
Jr. Member
Posts: 85
Joined: February 4th, 2011, 8:30 am
Contact:

Re: [Linux] Cleanup-script (Bash)

Post by Mar2zz »

When you make functions of it it's easier to add it to other postprocessingscripts in bash. Use for file in list do action done makes this easier to edit.
example:

Code: Select all

Cleanup () { #### Remove unwanted files
GARBAGE=".nfo .srr .sfv .nzb .jpg" #### Add or remove extensions here

for junk in $GARBAGE
do
find $1 -name *$junk -type f -exec rm -f {} \;
done
}
Cleanup
Last edited by Mar2zz on February 4th, 2011, 9:38 am, edited 1 time in total.
Post Reply