Page 1 of 1

[Linux] Script to remove nzb site url from folder name (Or anything else)

Posted: September 12th, 2008, 5:33 am
by mollydog
This will remove [nzbmatrix.com] from downloaded folder names. Its adapted from the useful clam virus scan script so they can be combined into one if you wished.

Hope its useful to someone!

Code: Select all

#! /bin/sh

BASENAME=`basename "$1"`

echo "Path to download is $1"
echo "Directory is $BASENAME"
echo "Stripped would be ${BASENAME%\[nzbmatrix.com\]}"

if [ "$BASENAME"=*\[nzbmatrix.com\]* ]; then
  echo 'Directory name contains [nzbmatrix.com]'
  echo "Renaming directory $BASENAME to ${BASENAME%\[nzbmatrix.com\]}"
  cd "$1"/..
  mv "$BASENAME" "${BASENAME%\[nzbmatrix.com\]}"
  else
  echo '[nzbmatrix.com] not present in title, all is well!'
fi

Re: [Linux] Script to remove nzb site url from folder name (Or anything else)

Posted: September 12th, 2008, 6:02 am
by mollydog
This is the two combined..

Code: Select all

#! /bin/sh

BASENAME=`basename "$1"`

echo "Path to download is $1"
echo "Directory is $BASENAME"
echo "Stripped would be ${BASENAME%\[nzbmatrix.com\]}"

if [ "$BASENAME"=*\[nzbmatrix.com\]* ]; then
  echo 'Directory name contains [nzbmatrix.com]'
  echo "Renaming directory $BASENAME to ${BASENAME%\[nzbmatrix.com\]}"
  cd "$1"/..
  mv "$BASENAME" "${BASENAME%\[nzbmatrix.com\]}"
  else
  echo '[nzbmatrix.com] not present in title, all is well!'
fi


FORCLAM="${1%\[nzbmatrix.com\]}"
LOGFILE="$FORCLAM/clamscan.log"
NEWBASE=`basename "$FORCLAM"`

echo "Path to scan for viruses is $FORCLAM"
/usr/bin/clamscan -i -l "$LOGFILE" -r "$FORCLAM"

if [ $? -eq 1 ]; then
  cd "$FORCLAM"/..
  mv "$NEWBASE" _INFECTED_"$NEWBASE"
fi

Re: [Linux] Script to remove nzb site url from folder name (Or anything else)

Posted: October 25th, 2008, 6:47 am
by twpux
Thanks, saves me a few minutes  ;D