regex - regex filename pattern

Discussion of Transmission that doesn't fit in the other categories
Post Reply
regex
Posts: 3
Joined: Fri Sep 07, 2012 8:13 pm

regex - regex filename pattern

Post by regex »

my bash script on download complete, it fires this bash script to fix bad file pattern which are not compatible on the terminal, this bash replaces white space with _ underscore

tested on Transmission 2.51 (13280) ubuntu 12.04 64bit works

stop bt daemon

/etc/init.d/transmission-daemon stop

make folders

Code: Select all

mkdir /var/www/tmp
mkdir /var/www/downloads      ---- < point your transmission download complete folder here

Code: Select all

chmod 755 /var/www/tmp
chmod 755 /var/www/downloads
chmod 755 /var/www/regex.sh 
create empty sh like this in terminal
nano regex.sh

past this inside

Code: Select all

#!/bin/bash
chmod 777 /var/www/downloads/*

sleep 5

find /var/www/downloads -regextype posix-egrep -regex '.*\.(avi|mkv|ogv|mp4)$' -exec mv "{}" /var/www/tmp/ \;

sleep 5

rm -rf /var/www/downloads/*
 
sleep 5

cd /var/www/tmp
for infile in *.*;
do 
#replace " - " with a single underscore.
NEWFILE1=`echo $infile | sed 's/\s-\s/_/g'`; 
#replace spaces with underscores
NEWFILE2=`echo $NEWFILE1 | sed 's/\s/_/g'`; 
#replace "-" dashes with underscores.
NEWFILE3=`echo $NEWFILE2 | sed 's/-/_/g'`; 
#remove exclamation points
NEWFILE4=`echo $NEWFILE3 | sed 's/!//g'`; 
#remove commas
NEWFILE5=`echo $NEWFILE4 | sed 's/,//g'`; 
mv "$infile" "/var/www/downloads/$NEWFILE5";
done;

open the settings.json and edit like this

Code: Select all

nano /var/lib/transmission-daemon/info/settings.json

Code: Select all

"download-dir": "/var/www/downloads",

Code: Select all

 "script-torrent-done-enabled": true,
  "script-torrent-done-filename": "var/www/regex.sh",

now,

Code: Select all

/etc/init.d/transmission-daemon reload 

Code: Select all

/etc/init.d/transmission-daemon restart
and finally reboot your Server

type this in terminal

Code: Select all

reboot

thats it, its working perfectly for me :D

hope it helps somebody
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: regex - regex filename pattern

Post by blacke4dawn »

Couple of personal objections and observations.

1) It seems more like it's combinations of characters (or single characters) that you don't like rather than not compatible, or you are using some very strange terminal.

2) You are removing the data of the torrent but not the entry of the torrent itself in Transmission.

3) Not using variables for the directories in your script for easy adaptation onto other systems.

4) Unnecessary use of sleep.

5) Please don't take this the wrong way but please read up more on the "Linux way" since it's apparent you have a strong Windows background (*.* for catching all file when only * is needed, and rebooting the machine).
regex
Posts: 3
Joined: Fri Sep 07, 2012 8:13 pm

Re: regex - regex filename pattern

Post by regex »

you are pretty right

file pattern when changed, and moved, it will no longer be seeded or shared, but that was the whole point when i started this, i wanted to move the file, and fix the filename

ubuntu terminal, does not understand for example

Code: Select all

 cat /var/www/tmp/this is a text file.txt 
but it does understand this

Code: Select all

cat /var/www/tmp/this_is_a_text_file.txt 
just discovered i can loop a bash script

Code: Select all

loop.sh

Code: Select all

#!/bin/sh
while true
do
#now we call second
 /var/www/cron.sh
 sleep 1800
done

Code: Select all

nohup ./loop.sh &
:shock: i love linux, oh yes i wrote the bash from windows putty haha :D
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: regex - regex filename pattern

Post by blacke4dawn »

regex wrote:ubuntu terminal, does not understand for example

Code: Select all

 cat /var/www/tmp/this is a text file.txt 
but it does understand this

Code: Select all

cat /var/www/tmp/this_is_a_text_file.txt 
Yes it does, you just need to tell it that the spaces are a part of the name by either escaping every space separately with a backslash or put the entire name within quotes.

So it would fully understand

Code: Select all

 cat "/var/www/tmp/this is a text file.txt" 
The best way for you to achieve that would be to put the variable name within quotes, which is a very good practice to always do when you are treating a bash-variables as strings.


And honestly, it would be better if you took a look at crontab if you want to run it at regular intervals.
regex
Posts: 3
Joined: Fri Sep 07, 2012 8:13 pm

Re: regex - regex filename pattern

Post by regex »

thanks :mrgreen:

yes i did look into crontab -e , it seems i can not figure that out yet so instead use online cronjob service fire every 2 hours :lol:

i used php exec bash,sh etc :D works pretty good .

but anyway this is getting off topic !
Post Reply