LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 09-21-2005, 01:41 PM   #1
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Rep: Reputation: 30
Symlink


I am creating a sh script and I need some help on how to make symlinks...

I have a folder /mnt/e/xxxxxx/ which contains several rar files. I also have /mnt/d/xxxxxx/ and I want to symlink all rar files (*.r*) to /mnt/d/xxxxx/... And I also want to rename them at the same time. So original.r01 becomes new.r01 and original.r02 becomes new.r02...

How can I do this?


I cant get ln -s to do it so I was thinking I might need to do a loop to do a ls | grep .r and then get one filename at the time and link it. But I am new to scripts and I am unsure how to do a loop to do that.




Thanks
 
Old 09-22-2005, 08:04 AM   #2
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
for i in mnt/e/xxx/*\.rar;do echo "renaming $i ...";mv "$i" ${i/original/new}; echo "linking ${i/original/new} ...";BASE=`basename "$i"`;ln -s ${i/original/new} mnt/d/xxx/${BASE/original/new};done

HTH
BEFORE:
$ ls -l mnt/e/xxx
total 0
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original01.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original02.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original03.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original04.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original05.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original06.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 original07.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:31 original08.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:31 original09.rar
AFTER:

$ ls -l mnt/e/xxx
total 0
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new01.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new02.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new03.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new04.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new05.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new06.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:30 new07.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:31 new08.rar
-rw-r--r-- 1 admin None 0 Sep 22 06:31 new09.rar

$ ls -l mnt/d/xxx
total 9
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new01.rar -> mnt/e/xxx/new01.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new02.rar -> mnt/e/xxx/new02.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new03.rar -> mnt/e/xxx/new03.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new04.rar -> mnt/e/xxx/new04.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new05.rar -> mnt/e/xxx/new05.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new06.rar -> mnt/e/xxx/new06.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new07.rar -> mnt/e/xxx/new07.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new08.rar -> mnt/e/xxx/new08.rar
lrwxrwxrwx 1 admin None 19 Sep 22 07:00 new09.rar -> mnt/e/xxx/new09.rar

Last edited by /bin/bash; 09-22-2005 at 08:07 AM.
 
Old 09-22-2005, 07:06 PM   #3
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Thank you, however the file extentions are, rar, r00, r01, r02 .....


I got the script to work I just have one problem now. Some times winrar will name files like part01.rar, part02.rar, part03.rar and so forth. I cant get it to work when they are named partxx.rar... Here is my script so far...


Code:
RELEASE=TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU
RELNAME=$(echo $RELEASE | cut -d/ -f2)
SERIE=$(echo $RELNAME | sed 's/\(.*\).[Ss][0-9][0-9][Ee][0-9][0-9].*/\1/')
EXTENSION=1
EXT=$(printf "%0.2d" $EXTENSION;);
for o in /mnt/e/glftpd/site/$RELEASE/*\.[Pp][Aa][Rr][Tt][0-9][0-9].r*;do {
        BASE=`basename "$o"`;
        echo "-s -f $o /mnt/tv/tv/TV/Latest/$SERIE.part$EXT.rar" >> /tmp/test.ln
        echo "Now processing ext part$EXT.rar for file $o filename is $BASE";
        EXTENSION=$(expr $EXTENSION + 1);
        EXT=$(printf "%0.2d" $EXTENSION;);
}
done
EXTENSION=0
EXT=$(printf "%0.2d" $EXTENSION;);
ONCE=0
for i in /mnt/e/glftpd/site/$RELEASE/*\.[rR][0-9][0-9];do {
        if [ "$ONCE" == "0" ]; then
                ls /mnt/e/glftpd/site/$RELEASE/ | grep .rar >> /tmp/rar.temp
                RAR=$(cat /tmp/rar.temp)
                echo "-s -f /mnt/e/glftpd/site/$RELEASE/$RAR /mnt/tv/tv/TV/Latest/$SERIE.rar" >> /tmp/test.ln
                ONCE=1
                rm -Rf /tmp/rar.temp
        fi
        BASE=`basename "$i"`;
        echo "-s -f $i /mnt/tv/tv/TV/Latest/$SERIE.r$EXT" >> /tmp/test.ln
        echo "Now processing ext $EXT for file $i filename is $BASE";
        EXTENSION=$(expr $EXTENSION + 1);
        EXT=$(printf "%0.2d" $EXTENSION;);
}
done

It will function but it will output a lot of crap as well (note I replaced ln with echo because I dont want to start linking yet until it is working)...

if I comment out the [Pp][Aa][Rr][Tt] section it will work flawless on folders containing rar, r01, r02 and so forth.

How ever if I uncomment it, it will also output the following,

-s -f /mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/*.[Pp][Aa][Rr][Tt][0-9][0-9].r* /mnt/tv/tv/TV/Latest/Las.Vegas.part01.rar <-- if I am running the script on a folder containing .rar, .r01, r02 files..

and if I run it on a folder containing part01.rar, part02.rar, part03.rar it will also output at the end:

-s -f /mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part01.rar
lost.s02e01.hr.hdtv.xvid.nbs.part02.rar
lost.s02e01.hr.hdtv.xvid.nbs.part03.rar
....
lost.s02e01.hr.hdtv.xvid.nbs.part48.rar
lost.s02e01.hr.hdtv.xvid.nbs.part49.rar
lost.s02e01.hr.hdtv.xvid.nbs.part50.rar /mnt/tv/tv/TV/Latest/Lost.rar
-s -f /mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/*.[rR][0-9][0-9] /mnt/tv/tv/TV/Latest/Lost.r00



I cant figure out why it would output this! Also the echo "Now processing ext $EXT for file $i filename is $BASE"; part is just for debugging, it will be removed later...

What am I doing wrong...


P.s I know the script looks like shit since I am new to this and I use alternativ methods to accomplish tasks which are concidered simple for experienced users...

Last edited by Fredde87; 09-22-2005 at 07:11 PM.
 
Old 09-23-2005, 08:19 AM   #4
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Quote:
Thank you, however the file extentions are, rar, r00, r01, r02
That doesn't change much, just use .r?? in your glob. Also to turn off case sensitive globbing use shopt -s nocaseglob

I'm having a hard time trying to figure out what you want to do. I suspect you you have files and some are named bla.bla.partxx.rar and some are named bla.bla.part01.rxx. The way it looks to me you want to rename all the files bla.bla.part01.rxx to bla.bla.partxx.rar. And also make a symlink. Then for the files with the rar extension you just want the symlink?

$ ls mnt/e/xxx
Las.Vegas.part01.r01 lost.s02e01.hr.hdtv.xvid.nbs.part01.rar
Las.Vegas.part01.r02 lost.s02e01.hr.hdtv.xvid.nbs.part02.rar
Las.Vegas.part01.r03 lost.s02e01.hr.hdtv.xvid.nbs.part03.rar
Las.Vegas.part01.r04 lost.s02e01.hr.hdtv.xvid.nbs.part04.rar
Las.Vegas.part01.r05 lost.s02e01.hr.hdtv.xvid.nbs.part05.rar
Las.Vegas.part01.r06 lost.s02e01.hr.hdtv.xvid.nbs.part06.rar
Las.Vegas.part01.r07 lost.s02e01.hr.hdtv.xvid.nbs.part07.rar
Las.Vegas.part01.r08 lost.s02e01.hr.hdtv.xvid.nbs.part08.rar
Las.Vegas.part01.r09 lost.s02e01.hr.hdtv.xvid.nbs.part09.rar
Las.Vegas.part01.r11 lost.s02e01.hr.hdtv.xvid.nbs.part11.rar

You would prolly need 2 loops since you are dealing with to separate situations. To rename the rxx files to partxx.rar would be like this:

$ for i in mnt/e/xxx/*\.r[0-9][0-9]
do
mv "$i" `echo ${i/part??\.r/part}.rar`
done

$ ls mnt/e/xxx
Las.Vegas.part01.rar lost.s02e01.hr.hdtv.xvid.nbs.part01.rar
Las.Vegas.part02.rar lost.s02e01.hr.hdtv.xvid.nbs.part02.rar
Las.Vegas.part03.rar lost.s02e01.hr.hdtv.xvid.nbs.part03.rar
Las.Vegas.part04.rar lost.s02e01.hr.hdtv.xvid.nbs.part04.rar
Las.Vegas.part05.rar lost.s02e01.hr.hdtv.xvid.nbs.part05.rar
Las.Vegas.part06.rar lost.s02e01.hr.hdtv.xvid.nbs.part06.rar
Las.Vegas.part07.rar lost.s02e01.hr.hdtv.xvid.nbs.part07.rar
Las.Vegas.part08.rar lost.s02e01.hr.hdtv.xvid.nbs.part08.rar
Las.Vegas.part09.rar lost.s02e01.hr.hdtv.xvid.nbs.part09.rar
Las.Vegas.part11.rar lost.s02e01.hr.hdtv.xvid.nbs.part11.rar

Now you can do all the symlinks in one loop:
$ for i in mnt/e/xxx/*\.rar
do
BASE=`basename $i`
ln -s "$i" mnt/d/xxx/$BASE
done

$ ls mnt/d/xxx
Las.Vegas.part01.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part01.rar@
Las.Vegas.part02.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part02.rar@
Las.Vegas.part03.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part03.rar@
Las.Vegas.part04.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part04.rar@
Las.Vegas.part05.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part05.rar@
Las.Vegas.part06.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part06.rar@
Las.Vegas.part07.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part07.rar@
Las.Vegas.part08.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part08.rar@
Las.Vegas.part09.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part09.rar@
Las.Vegas.part11.rar@ lost.s02e01.hr.hdtv.xvid.nbs.part11.rar@

<edit> If this isn't correct then you'll have to provide some sort of directory listing so I can get a better ideal of what you want to do.

Also for making the symlinks you could just use lndir which can symlink an entire directory tree and all files in it.

Last edited by /bin/bash; 09-23-2005 at 08:32 AM.
 
Old 09-23-2005, 09:20 AM   #5
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Ok, here are some examples, remember that there is two kinds of situations.


Situation 1:

I want to create a symlink from:

/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part01.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part01.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part02.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part02.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part03.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part03.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part04.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part04.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part05.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part05.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part06.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part06.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part07.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part07.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part08.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part08.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part09.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part09.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part10.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part10.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part11.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part11.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part12.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part12.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part13.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part13.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part14.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part14.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part15.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part15.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part16.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part16.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part17.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part17.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part18.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part18.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part19.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part19.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part20.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part20.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part21.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part21.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part22.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part22.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part23.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part23.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part24.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part24.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part25.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part25.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part26.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part26.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part27.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part27.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part28.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part28.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part29.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part29.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part30.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part30.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part31.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part31.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part32.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part32.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part33.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part33.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part34.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part34.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part35.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part35.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part36.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part36.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part37.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part37.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part38.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part38.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part39.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part39.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part40.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part40.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part41.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part41.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part42.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part42.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part43.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part43.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part44.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part44.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part45.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part45.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part46.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part46.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part47.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part47.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part48.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part48.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part49.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part49.rar
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part50.rar --> /mnt/tv/tv/TV/Latest/Lost/Lost.part50.rar




Situation 2:

/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.rar --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.rar
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r00 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r00
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r01 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r01
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r02 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r02
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r03 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r03
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r04 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r04
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r05 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r05
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r06 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r06
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r07 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r07
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r08 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r08
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r09 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r09
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r10 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r10
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r11 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r11
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r12 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r12
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r13 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r13
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r14 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r14
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r15 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r15
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r16 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r16
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r17 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r17
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r18 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r18
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r19 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r19
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r20 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r20
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r21 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r21
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r22 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r22
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r23 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r23
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r24 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r24
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r25 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r25
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r26 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r26
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r27 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r27
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r28 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r28
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r29 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r29
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r30 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r30
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r31 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r31
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r32 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r32
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r33 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r33
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r34 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r34
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r35 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r35
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r36 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r36
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r37 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r37
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r38 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r38
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r39 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r39
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r40 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r40
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r41 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r41
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r42 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r42
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r43 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r43
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r44 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r44
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r45 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r45
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r46 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r46
/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/ctu-lv301.r47 --> /mnt/tv/tv/TV/Latest/Las.Vegas/Las.Vegas.r47


Does that help?
 
Old 09-23-2005, 06:09 PM   #6
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
OK That helps alot:

Code:
#!/bin/bash
#Situation 1:
#Create symlink:
FROM="/mnt/tv/tv/TV/Latest/Lost"
TO="/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS"

for i in $FROM/*\.rar
do
  BASE=`basename "$i"`
  ln -s "$i" $TO/${BASE/Lost/lost.s02e01.hr.hdtv.xvid.nbs}
done

#Situation 2:
#Symlink with rename files with .rXX extension to partXX.rar
#First step is to increment the sequence to make room for
# the oddball Las.Vegas.rar file
FROM="/mnt/tv/tv/TV/Latest/Las.Vegas"
TO="/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU"
for i in $FROM/*\.r[0-9][0-9]
do
  BASE=`basename "$i"`
  num=$(($num+1))
  NUM=$(printf "%0.2d" $num;)
  ln -s $i $TO/${BASE/Las.Vegas.r??/ctu-lv301.part$NUM}.rar
done
#This links the oddball file LasVegas.rar
ln -s $FROM/Las.Vegas.rar $TO/ctu-lv301.part00.rar
<edit> Disable smilies :)

Oops corrected the paths. I was using relative paths in my home directory.

Last edited by /bin/bash; 09-23-2005 at 07:35 PM.
 
Old 09-23-2005, 08:57 PM   #7
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Only one problem, it is the the way around :P

The file that I already have is /mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.partXX.rar and it should be linked to the new location /mnt/tv/tv/TV/Latest/Lost.partXX.rar....


Also .rXX shouldnt be renamed to partXX.rar... It should still keep the original file extension, the only thing I want to change is the name ("lost.s02e01.hr.hdtv.xvid.nbs" to just "lost")...


Thanks for the help! I reallly appreciate it!
 
Old 09-24-2005, 03:38 AM   #8
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Quote:
Only one problem, it is the the way around :P
When you look at a symlink the file the arrow "-->" points from is the link and the file the arrow "-->" points to is the actual file.

So if all you want to do is symlink those files then the way I wrote it the first time should work, just change the FROM and TO and a slight modification to the link statement.

FROM="/mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU"
TO="/mnt/tv/tv/TV/Latest/Las.Vegas"
for i in $FROM/*\.r??
do
BASE=`basename "$i"`
ln -s "$i" $TO/${BASE/ctu\-lv301/Las\.Vegas}
done

You can also make your file selection more specific like this:
for i in $FROM/*\.r[a0-9][r0-9]
Now you will only link files with .rar, .rXr, .raX or .rXX where X is a digit 0-9.
 
Old 09-24-2005, 05:41 AM   #9
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
I tried the script now, the good part is that linking .rXX files will now work. With the exception of a bit being added to the end linking /mnt/e/glftpd/site/TV-HRHD/Las.Vegas.S03E01.HR.HDTV.AC3.5.1.XviD-CTU/Las.Vegas.rar with /mnt/tv/tv/TV/Latest/Las.Vegas/ctu-lv301.part00.rar....


When it comes to the partXX.rar part it doesnt work at all, it will link as following:
/mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS/lost.s02e01.hr.hdtv.xvid.nbs.part01.rar to /mnt/tv/tv/TV/Latest/Lost/lost.s02e01.hr.hdtv.xvid.nbs.part01.rar




edit: Just to be sure I will post a list of all the files in /mnt/e/glftpd/site/TV-HRHD/Lost.S02E01.HR.HDTV.AC3.5.1.XviD-NBS


lost.s02e01.hr.hdtv.ac3.5.1.xvid-nbs.nfo
lost.s02e01.hr.hdtv.xvid.nbs.part01.rar
lost.s02e01.hr.hdtv.xvid.nbs.part01.sfv
lost.s02e01.hr.hdtv.xvid.nbs.part02.rar
lost.s02e01.hr.hdtv.xvid.nbs.part03.rar
lost.s02e01.hr.hdtv.xvid.nbs.part04.rar
lost.s02e01.hr.hdtv.xvid.nbs.part05.rar
lost.s02e01.hr.hdtv.xvid.nbs.part06.rar
lost.s02e01.hr.hdtv.xvid.nbs.part07.rar
lost.s02e01.hr.hdtv.xvid.nbs.part08.rar
lost.s02e01.hr.hdtv.xvid.nbs.part09.rar
lost.s02e01.hr.hdtv.xvid.nbs.part10.rar
lost.s02e01.hr.hdtv.xvid.nbs.part11.rar
lost.s02e01.hr.hdtv.xvid.nbs.part12.rar
lost.s02e01.hr.hdtv.xvid.nbs.part13.rar
lost.s02e01.hr.hdtv.xvid.nbs.part14.rar
lost.s02e01.hr.hdtv.xvid.nbs.part15.rar
lost.s02e01.hr.hdtv.xvid.nbs.part16.rar
lost.s02e01.hr.hdtv.xvid.nbs.part17.rar
lost.s02e01.hr.hdtv.xvid.nbs.part18.rar
lost.s02e01.hr.hdtv.xvid.nbs.part19.rar
lost.s02e01.hr.hdtv.xvid.nbs.part20.rar
lost.s02e01.hr.hdtv.xvid.nbs.part21.rar
lost.s02e01.hr.hdtv.xvid.nbs.part22.rar
lost.s02e01.hr.hdtv.xvid.nbs.part23.rar
lost.s02e01.hr.hdtv.xvid.nbs.part24.rar
lost.s02e01.hr.hdtv.xvid.nbs.part25.rar
lost.s02e01.hr.hdtv.xvid.nbs.part26.rar
lost.s02e01.hr.hdtv.xvid.nbs.part27.rar
lost.s02e01.hr.hdtv.xvid.nbs.part28.rar
lost.s02e01.hr.hdtv.xvid.nbs.part29.rar
lost.s02e01.hr.hdtv.xvid.nbs.part30.rar
lost.s02e01.hr.hdtv.xvid.nbs.part31.rar
lost.s02e01.hr.hdtv.xvid.nbs.part32.rar
lost.s02e01.hr.hdtv.xvid.nbs.part33.rar
lost.s02e01.hr.hdtv.xvid.nbs.part34.rar
lost.s02e01.hr.hdtv.xvid.nbs.part35.rar
lost.s02e01.hr.hdtv.xvid.nbs.part36.rar
lost.s02e01.hr.hdtv.xvid.nbs.part37.rar
lost.s02e01.hr.hdtv.xvid.nbs.part38.rar
lost.s02e01.hr.hdtv.xvid.nbs.part39.rar
lost.s02e01.hr.hdtv.xvid.nbs.part40.rar
lost.s02e01.hr.hdtv.xvid.nbs.part41.rar
lost.s02e01.hr.hdtv.xvid.nbs.part42.rar
lost.s02e01.hr.hdtv.xvid.nbs.part43.rar
lost.s02e01.hr.hdtv.xvid.nbs.part44.rar
lost.s02e01.hr.hdtv.xvid.nbs.part45.rar
lost.s02e01.hr.hdtv.xvid.nbs.part46.rar
lost.s02e01.hr.hdtv.xvid.nbs.part47.rar
lost.s02e01.hr.hdtv.xvid.nbs.part48.rar
lost.s02e01.hr.hdtv.xvid.nbs.part49.rar
lost.s02e01.hr.hdtv.xvid.nbs.part50.rar


these is the most unregular situation, in the most common situation it will look like this:

ctu-lv301.r00
ctu-lv301.r01
ctu-lv301.r02
ctu-lv301.r03
ctu-lv301.r04
ctu-lv301.r05
ctu-lv301.r06
ctu-lv301.r07
ctu-lv301.r08
ctu-lv301.r09
ctu-lv301.r10
ctu-lv301.r11
ctu-lv301.r12
ctu-lv301.r13
ctu-lv301.r14
ctu-lv301.r15
ctu-lv301.r16
ctu-lv301.r17
ctu-lv301.r18
ctu-lv301.r19
ctu-lv301.r20
ctu-lv301.r21
ctu-lv301.r22
ctu-lv301.r23
ctu-lv301.r24
ctu-lv301.r25
ctu-lv301.r26
ctu-lv301.r27
ctu-lv301.r28
ctu-lv301.r29
ctu-lv301.r30
ctu-lv301.r31
ctu-lv301.r32
ctu-lv301.r33
ctu-lv301.r34
ctu-lv301.r35
ctu-lv301.r36
ctu-lv301.r37
ctu-lv301.r38
ctu-lv301.r39
ctu-lv301.r40
ctu-lv301.r41
ctu-lv301.r42
ctu-lv301.r43
ctu-lv301.r44
ctu-lv301.r45
ctu-lv301.r46
ctu-lv301.r47
ctu-lv301.rar
ctu-lv301.sfv
las.vegas.301-ctu.nfo


Remember that the script will run on all kinds of folders, not just the two examples I have provided. So the script has to first check what situation it is and the run the appropriate actions...


Thanks!

Last edited by Fredde87; 09-24-2005 at 06:11 AM.
 
Old 09-25-2005, 09:01 AM   #10
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Quote:
Remember that the script will run on all kinds of folders, not just the two examples I have provided. So the script has to first check what situation it is and the run the appropriate actions...
If thats the case you'll need to set up some type of config file which you can edit to add/remove paths and filenames in. I was bored so I went ahead and wrote something that you could use as a starting point and modify as you need.

The script symlink reads a config file symlink.conf which contains 5 entries:
# Copy this to symlink.conf and uncomment the examples or create your own.
# situation = tells program wether to rename the extension when linking.
# FROM = Directory where files are stored.
# TO = Directory where simlinks will be made
# ORIGINAL = The part of the original filename to be removed
# NEW = This will replace the ORIGINAL string in new symlink filename
# situation FROM TO ORIGINAL NEW
# Example 1
# 1 /mnt/e/dir2/show1 /mnt/tv/show/Lost lost.s02e01.hr.hdtv.xvid.nbs Lost
# Example 2
# 2 /mnt/e/dir1/show1 /mnt/tv/show/LasVegas ctu\-lv301\.r?? Las\.Vegas\.part
# Example 3
# 1 /mnt/e/dir1/show2 /mnt/tv/show/Simpsons name.of.show-S03E01 Simpsons
# Example 4
# 2 /mnt/e/dir2/show2 /mnt/tv/show/AnotherWorld S02E01\.r?? part

I have some dummy files setup to demonstrate:

mnt/e/dir1/show1:
ctu-lv301.r00
ctu-lv301.r01
ctu-lv301.r02
ctu-lv301.r03
ctu-lv301.r04
ctu-lv301.r05
ctu-lv301.r06
ctu-lv301.r07
ctu-lv301.r08
ctu-lv301.r09
ctu-lv301.r11
ctu-lv301.r12
ctu-lv301.rar

mnt/e/dir1/show2:
name.of.show-S03E01.part00.rar
name.of.show-S03E01.part01.rar
name.of.show-S03E01.part02.rar
name.of.show-S03E01.part03.rar
name.of.show-S03E01.part04.rar
name.of.show-S03E01.part05.rar
name.of.show-S03E01.part06.rar
name.of.show-S03E01.part07.rar
name.of.show-S03E01.part08.rar
name.of.show-S03E01.part09.rar
name.of.show-S03E01.part11.rar
name.of.show-S03E01.part12.rar

mnt/e/dir2/show1:
lost.s02e01.hr.hdtv.xvid.nbs.part00.rar
lost.s02e01.hr.hdtv.xvid.nbs.part01.rar
lost.s02e01.hr.hdtv.xvid.nbs.part02.rar
lost.s02e01.hr.hdtv.xvid.nbs.part03.rar
lost.s02e01.hr.hdtv.xvid.nbs.part04.rar
lost.s02e01.hr.hdtv.xvid.nbs.part05.rar
lost.s02e01.hr.hdtv.xvid.nbs.part06.rar
lost.s02e01.hr.hdtv.xvid.nbs.part07.rar
lost.s02e01.hr.hdtv.xvid.nbs.part08.rar
lost.s02e01.hr.hdtv.xvid.nbs.part09.rar
lost.s02e01.hr.hdtv.xvid.nbs.part11.rar
lost.s02e01.hr.hdtv.xvid.nbs.part12.rar

mnt/e/dir2/show2:
Another.World.S02E01.r00
Another.World.S02E01.r01
Another.World.S02E01.r02
Another.World.S02E01.r03
Another.World.S02E01.r04
Another.World.S02E01.r05
Another.World.S02E01.r06
Another.World.S02E01.r07
Another.World.S02E01.r08
Another.World.S02E01.r09
Another.World.S02E01.r11
Another.World.S02E01.r12
Another.World.S02E01.rar

So we have both types of situations here. In the 2 #1-Situations you have partXX.rar files, so all we do is rename the symlinks. We also have 2 #2-Situations where we have .rXX + one oddball .rar files, in this situation we have to rename the file extension after we increment the sequence by 1 so we have room for the oddball file with the .rar extension.


And here are partitial directory listings after running the script:

mnt/tv/show/AnotherWorld:
total 14
lrwxrwxrwx 1 admin None 41 Sep 25 07:46 Another.World.part00.rar -> mnt/e/dir2/
show2/Another.World.S02E01.rar
lrwxrwxrwx 1 admin None 41 Sep 25 07:46 Another.World.part01.rar -> mnt/e/dir2/
show2/Another.World.S02E01.r00
...
lrwxrwxrwx 1 admin None 41 Sep 25 07:46 Another.World.part13.rar -> mnt/e/dir2/
show2/Another.World.S02E01.r12

mnt/tv/show/LasVegas:
total 14
lrwxrwxrwx 1 admin None 30 Sep 25 07:46 Las.Vegas.part00.rar -> mnt/e/dir1/show
1/ctu-lv301.rar
lrwxrwxrwx 1 admin None 30 Sep 25 07:46 Las.Vegas.part01.rar -> mnt/e/dir1/show
1/ctu-lv301.r00
...
lrwxrwxrwx 1 admin None 30 Sep 25 07:46 Las.Vegas.part13.rar -> mnt/e/dir1/show
1/ctu-lv301.r12

mnt/tv/show/Lost:
total 13
lrwxrwxrwx 1 admin None 56 Sep 25 07:46 Lost.part00.rar -> mnt/e/dir2/show1/los
t.s02e01.hr.hdtv.xvid.nbs.part00.rar
lrwxrwxrwx 1 admin None 56 Sep 25 07:46 Lost.part01.rar -> mnt/e/dir2/show1/los
t.s02e01.hr.hdtv.xvid.nbs.part01.rar
...
lrwxrwxrwx 1 admin None 56 Sep 25 07:46 Lost.part12.rar -> mnt/e/dir2/show1/los
t.s02e01.hr.hdtv.xvid.nbs.part12.rar

mnt/tv/show/Simpsons:
total 13
lrwxrwxrwx 1 admin None 47 Sep 25 07:46 Simpsons.part00.rar -> mnt/e/dir1/show2
/name.of.show-S03E01.part00.rar
lrwxrwxrwx 1 admin None 47 Sep 25 07:46 Simpsons.part01.rar -> mnt/e/dir1/show2
/name.of.show-S03E01.part01.rar
...
lrwxrwxrwx 1 admin None 47 Sep 25 07:46 Simpsons.part12.rar -> mnt/e/dir1/show2
/name.of.show-S03E01.part12.rar



KNOWN BUGS:
As you can see the script works: It will give an error if you designate a FROM directory as situation2 and it has more than 1 .rar file. If there are more than one .rar in a situation2 directory files it will only find and link the one which matches the other files in the directory.

And here is the script, and the config file:

symlink
Code:
#!/bin/bash
#symlink
CONFIG=symlink.conf

situation1 () {
[ ! -d $FROM ] && echo "Dir $FROM doesn\'t exist, exiting..." && exit
[ ! -d $TO ] && echo "Making directory $TO" && mkdir -p $TO
for i in $FROM/*\.rar
do 
  BASE=`basename "$i"`
  # For troubleshoot uncomment next line
  # echo "linking ln -s "$i" $TO/${BASE/$ORIGINAL/$NEW}"
  # For troubleshoot comment next line
  ln -s "$i" $TO/${BASE/$ORIGINAL/$NEW}
done
}

situation2 () {
[ ! -d $FROM ] && echo "Dir $FROM doesn\'t exist, exiting..." && exit
[ ! -d $TO ] && echo "Making directory $TO" && mkdir -p $TO
num=0
for i in $FROM/*\.r[0-9][0-9]
do
  BASE=`basename "$i"`
  num=$(($num+1))
  NUM=$(printf "%0.2d" $num)
  # For troubleshoot uncomment next line
  # echo "linking ln -s $i $TO/${BASE/$ORIGINAL/$NEW$NUM.rar}"
  # For troubleshoot comment next line
  ln -s $i $TO/${BASE/$ORIGINAL/$NEW$NUM.rar}
done
if [ -f $FROM/*.rar ] 
then 
  BASE=`basename "$i"`
  NEW=$NEW"00"
  # For troubleshoot uncomment next line
  # echo "linking ln -s $FROM/*.rar $TO/${BASE/$ORIGINAL/$NEW.rar}"
  # For troubleshoot comment next line
  ln -s $FROM/*.rar $TO/${BASE/$ORIGINAL/$NEW.rar}
fi

FILE=${BASE/\.r[0-9][0-9]/\.rar}
if [ -f $FROM/$FILE ] 
then 
  NEW=$NEW"00"
  # For troubleshoot uncomment next line
  # echo "linking ln -s $FROM/$FILE $TO/${FILE/$ORIGINAL/$NEW.rar}"
  # For troubleshoot comment next line
  ln -s $FROM/$FILE $TO/${FILE/$ORIGINAL/$NEW.rar}
fi

}

# This part reads the config file and assigns the 
# variables used by the rest of the script.
# NOTE: arrays are 0 based therefore array[0] 
#       is the situation flag.
grep [^#] $CONFIG|while read #Dont read commented lines.
do
	array=( $( echo "$REPLY" ) )
	  situation="${array[0]}"
	  FROM="${array[1]}"
	  TO="${array[2]}"
	  ORIGINAL="${array[3]}"
	  NEW="${array[4]}"
	case $situation in
	  1 )
	  situation1
	  ;;
	  2 )
	  situation2
	  ;;
	esac
done
situation.conf
Code:
# Symlink config file. 
# situation = tells program wether to rename the extension when linking.
# FROM = Directory where files are stored.
# TO = Directory where simlinks will be made
# ORIGINAL = The part of the original filename to be removed
# NEW = This will replace the ORIGINAL string in new symlink filename
# situation FROM TO ORIGINAL NEW
# Examples
# 2 mnt/e/dir1/show1 mnt/tv/show/LasVegas ctu\-lv301\.r?? Las\.Vegas\.part
# 1 mnt/e/dir1/show2 mnt/tv/show/Simpsons name.of.show-S03E01 Simpsons
# 1 mnt/e/dir2/show1 mnt/tv/show/Lost lost.s02e01.hr.hdtv.xvid.nbs Lost
# 2 mnt/e/dir2/show2 mnt/tv/show/AnotherWorld S02E01\.r?? part
<edit> The comments about troubleshooting are for trying to get your ORIGINAL and NEW strings set in the config file. Just comment the line with the ln command and uncomment the echo command and you can run the script untill you figure out how to make it work the way you want.

<edit> Version .001 - Fixed KNOWN BUG
RED = Remove
GREEN = Add

Last edited by /bin/bash; 09-25-2005 at 09:55 AM.
 
Old 09-25-2005, 02:43 PM   #11
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Thank you! Works great! I can't belive you put that together!...


... However :P

If I want to link a .partXX.rar situation to .rXX, how would I do this? Also note that there is not .part00.rar... Winrar will start the first file of with .part01.rar... It is just in the "old" style (.rXX) that it uses 00...

Also, a great feature would be if it unlinked all the previous files beforing linking, using -f in ln would overwrite if it exists. But the problem would arise if there is 49 rar files but 50 rar files the in old one. This would remove all old 49 but leave an old file called .part50.rar....



I did some testing of winrar and a problem accured. For some reason it isnt possible to rename .rXX files to .partXX.rar, winrar will not open them. However it is possible to rename .partXX.rar files to .rXX. So I think to goal should that they should end up in the TO path as .rXX always regardless of previous format.
Thanks!
 
Old 09-25-2005, 10:32 PM   #12
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Quote:
Also, a great feature would be if it unlinked all the previous files beforing linking, using -f in ln would overwrite if it exists. But the problem would arise if there is 49 rar files but 50 rar files the in old one. This would remove all old 49 but leave an old file called .part50.rar....
#To remove broken links from $TO directory
remove_broken_links () {
for f in $(find $TO -type l)
do
if [ ! -e "$f" ]
then
echo "Removing broken link $f..."
rm -f $f
fi
done
}

Put the above function in the script and call it just before the case loop.
Code:
	array=( $( echo "$REPLY" ) )
	  situation="${array[0]}"
	  FROM="${array[1]}"
	  TO="${array[2]}"
	  ORIGINAL="${array[3]}"
	  NEW="${array[4]}"
          remove_broken_links
	case $situation in
	  1 )
	  situation1
	  ;;
	  2 )
	  situation2
	  ;;
	esac
Code:
If I want to link a .partXX.rar situation to .rXX, how would I do this? Also note that there is not .part00.rar... Winrar will start the first file of with .part01.rar... It is just in the "old" style (.rXX) that it uses 00...
Thats the nice thing about the config file. Now you can create more new situations and add them to the script.

situation3 () {
[ ! -d $FROM ] && echo "Dir $FROM doesn't exist, exiting..." && exit
[ ! -d $TO ] && echo "Making directory $TO" && mkdir -p $TO
for i in $FROM/*\.rar
do
BASE=`basename "$i"`
BASE=${BASE/$ORIGINAL/$NEW}
# For troubleshoot uncomment next line
# echo "linking ln -s "$i" $TO/${BASE/.rar}"
# For troubleshoot comment next line
ln -s "$i" $TO/${BASE/.rar}
done
}

Put the above code after situation2 () function. Then add another case segment:

case $situation in
1 )
situation1
;;
2 )
situation2
;;
3 )
situation3
;;
esac

And the config file wouls look something like this:
Using the lost example...
To link lost.s02e01.hr.hdtv.xvid.nbs.part00.rar to Lost.r00
symlink.conf
3 mnt/e/dir2/show1 mnt/tv/show/Lost lost.s02e01.hr.hdtv.xvid.nbs.part Lost.r


NOTE: I havent tested this, but I'll do that tomorrow. Gotta get up early to go to work, need sleep.... zzzzzzz

Last edited by /bin/bash; 09-25-2005 at 10:34 PM.
 
Old 09-26-2005, 05:31 AM   #13
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
The new situation3 seems to work OK. Notice there is not much difference in the config file, for situation1 vs. situation3.

1 mnt/e/dir2/show1 mnt/tv/show/Lost lost.s02e01.hr.hdtv.xvid.nbs Lost
3 mnt/e/dir2/show1 mnt/tv/show/Lost lost.s02e01.hr.hdtv.xvid.nbs.part Lost.r
 
Old 09-27-2005, 03:40 AM   #14
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Thank you! I will try this when I get home tonight.

If it does work then I own you a huge favor! Thanks!!!
 
Old 09-30-2005, 09:06 PM   #15
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Sorry I have been swamped with stuff to do this week. I finally had some time to test the script and it looks good. However the only problem with linking .partXX.rar to .rXX is that the oddball .rar is not created...

.part01.rar needs to be symlinked to .rar
and part02.rar needs to be symlinked to .r00
and part03.rar needs to be sylinked to .r01

and so forth.

Any quick fix to solve this?

Also I am getting confused, I thought that it was possible to link .rXX to .rXX but I cant get it to work now, did I mess something up or was I dreaming that it worked? :P


Thx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Symlink issues mngmd Linux - Software 1 09-12-2005 07:19 AM
where is symlink? guitarfella Slackware 3 12-04-2004 08:34 AM
symlink mikedelo Linux - Software 2 03-28-2004 01:32 PM
symlink evannextel Linux - Newbie 1 09-17-2003 04:54 PM
Symlink Mestax Linux - Newbie 3 09-04-2003 01:07 PM


All times are GMT -5. The time now is 09:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration