Using symlinks with the NTV550

Here's the place for announcements & news
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

ok Ian. Finally got back to this Symlink thing.

So I took your .txt file and edited it as I thought proper.
after I had finished, saved and put it in the folder of my choice on my NAS, I run "chmod a+x myscriptname.txt" via Putty (skipped sudo, as I had logged in as admin and there were no sudo installed).
and then launched, as said "./myscriptname.txt".
At this point it gave me an error "/bin/bash^M: bad interpreter: No such file or directory". After some quick googling I guess I found out the reason for this mistake - I took your .txt file and edited it in Notepad on my Win7 machine. Turns out, it is not good for Linux (I told you I am a total nooby :)). So as I read - in order to fix the file I have to run "dos2unix" to fix the file. So I run "dos2unix myscriptname.txt" and it sort of fixed the previous error, but I am afraid, it broke the file in some other way (or it was not correct the way I built it). As when i run it, for each line it gave smth like this:

Code: Select all

Creating Links in /share/HDA_DATA/SymLinks/Sci-Fi for everything found in folder: /share/HDA_DATA/Multimedia/!Movies/Sci-Fi
BusyBox v1.01 (2011.08.03-17:58+0000) multi-call binary

Usage: find [PATH...] [EXPRESSION]

Search for files in a directory hierarchy.  The default PATH is
the current directory; default EXPRESSION is '-print'

EXPRESSION may consist of:
        -follow         Dereference symbolic links.
        -name PATTERN   File name (leading directories removed) matches PATTERN.
        -print          Print (default and assumed).

        -type X         Filetype matches X (where X is one of: f,d,l,b,c,...)
        -perm PERMS     Permissions match any of (+NNN); all of (-NNN);
                        or exactly (NNN)
        -mtime TIME     Modified time is greater than (+N); less than (-N);
                        or exactly (N) days

I attach both the files - one before running dos2unix (1.txt) and the other - after (2.txt). Can you pls tell me, what is the problem there?

Also few additional questions:

1) how to find what is the path from my Linux NAS to Windows Workstation (in the same network) -
for putting it in createsymlinks file?
2) what happens if from two different Sourcefolders there are two subfolders with the same name -
how will they be displayed in Destfolder? Their contents will simply merge? What if there are file names
with the same names?
3) what's the simplest and the correct way to delete all symlinks?
Attachments
2.txt
after dos2unix
(9.7 KiB) Downloaded 414 times
1.txt
before dos2unix (edited in Notepad)
(9.7 KiB) Downloaded 421 times
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Using symlinks with the NTV550

Post by Ian »

Hi,

I'll have a good look through your script and see if I can work out what's going on. It's possible that the commands in the OS on your NAS work differently. I'll look at your script more closely and get back to you.

To remove all existing symlinks (assuming the script actually created some) then issue the following command after switching into the folder with the symlinks in it:

Code: Select all

find * -mindepth 0 -type l | while read file;do rm "$file";done
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

well, actually i think that is the thing:

this find command with the options provided does not work - there is no "-mindepth" option available when i run this command on my NAS

Code: Select all

find * -mindepth 0 -type l | while read file;do rm "$file";done


it gives again the same thing:

Code: Select all

BusyBox v1.01 (2011.08.03-17:58+0000) multi-call binary

Usage: find [PATH...] [EXPRESSION]

Search for files in a directory hierarchy.  The default PATH is
the current directory; default EXPRESSION is '-print'

EXPRESSION may consist of:
        -follow         Dereference symbolic links.
        -name PATTERN   File name (leading directories removed) matches PATTERN.
        -print          Print (default and assumed).

        -type X         Filetype matches X (where X is one of: f,d,l,b,c,...)
        -perm PERMS     Permissions match any of (+NNN); all of (-NNN);
                        or exactly (NNN)
        -mtime TIME     Modified time is greater than (+N); less than (-N);
                        or exactly (N) days


above are all the possible options and -mindepth nor -maxdepth is not listed among them. Can I somehow add them to my system (perhaps via ipkg package) or - in worst case scenario - perhaps they are not needed at all and can be somehow substituted? what exactly do these mindepth and maxdepth do?

running uname -a returns the following:
Linux Little-Sun 2.6.33.2 #1 Tue Aug 16 06:01:59 CST 2011 armv5tel unknown
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

well, ok. sorted that one out.
turns out, i have some pretty limited busybox version on my NAS, so i had to install findutils and after that i replaced every 'find' in your script with '/opt/bin/find'
and now it works! :))

however, there are some problems the way I wanted it to be and the way it is now..
1) First of all, I want to remove all the symlinks created with the script file. I had made a structure with separate folder 'Symlinks' and separate subfolders in it (!Documentaries, Action etc.). When running command line when in 'Symlinks' folder:

Code: Select all

/opt/bin/find * -mindepth 0 -type l | while read file;do rm "$file";done


it does give me a message:
/opt/bin/find: invalid predicate `!Documentaries'

How can I fix this command line so it does delete all symlinks in all the subfolders of 'Symlinks' folder below?

ok. fixed that with this command - it works fine when run in 'Symlinks' folder:

Code: Select all

/opt/bin/find . -mindepth 0 -type l -exec rm -f {} \;

still don't know what was wrong with your suggested command though. apparently it needs to be fixed in some way to process "!Foldername" like folders


2) Now to the way I wanted it to create the symlinks - is it possible that when i specify sourcefolder, it creates links for all folders and files in it, while keeping the source folder structure (just as mapping the drive would work)?
currently, it works very strangely - for some folders it has worked correctly, for some folders it has doubled the entries with putting the link of subfolder in the basic DestFolder as well. For example, If I had a folder named 'TV.Series.1998' with 'Season1' and 'Season2' in it - in 'Symlinks' folder it first created (linked) a folder 'TV.Series.1998' (with 'Season1' and 'Season2' in it) and then right besides created (linked) as well 'Season1' and 'Season2'. Of course, it also does not link files that were not in subfolders but were directly in SourceFolder (I'd like it to link these files as well).

first part of problem kind of solved with putting the first number after TRUE to zero (correct me if i am wrong):

Code: Select all

CreateTheLinks 'TRUE' 0 0 "$DestFolder" "${SourceFolders[@]}"

however, the second part still remains - all files that are not in folders but simply in SourceFolder are not linked. How do I do that?


3) i guess this one is linked to previous question - I tried to create a new file in one of symlinked SourceFolders. I thought the new folder should have been shown automatically under the respective Symlinks folder, but no luck - it does not show there. What have I done wrong? (pls see the previous script files attached, it's just those things mentioned above that I have edited in them).

have no solution to this currently

4) how to make the script work normally in an occasion where two Sourcefolders have subfolders with the same name? Currently, the script works that way that in DestFolder it creates this CommonNameSubfolder with its contents from first Sourcefolder and then from the second Sourcefolder it puts the second CommonNameSubfolder under the first CommonNameSubfolder (so it is like Folder\CommonNameSubfolder\CommonNameSubfolder). I would like it to merge contents of these subfolders, not place them one under another.

have no solution to this currently

5) also - what happens if i simply delete files from windows explorer (in Symlinks folder - DestFolder)? Will it simply delete the symlinks or will it delete / damage the original file as well?

as far as i understand, it should delete those symlinks, not original underlying files this way, but i'm not completely sure

Thank you for your help in advance, and sorry for such amounts of text.
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Using symlinks with the NTV550

Post by Ian »

Hi there,

You seem to be making good progress :thumbup:

Rather than me try and re-create your structures here it's probably quicker if you play around with the maxdepth setting. It's the first argument in the CreateTheLinks line. So, is the "1" in:

Code: Select all

CreateTheLinks 'TRUE' 1 0 "$DestFolder" "${SourceFolders[@]}"


You're correct, the TRUE/FALSE argument is for removing existing links in the DestFolder. You'd specify FALSE if you're adding additional links to a folder. So, the first call would be TRUE (to clear all existing links) and the second call would be FALSE to add additional links to the same folder.

It's worth playing with the mindepth setting too (the "0" in the command above). This may help where files in the top of the structure are not being linked.

You can delete any Symlinks using Windows Explorer without affecting the original files. They will remain intact.

Good luck. :thumbup:

Ian.
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

thanks Ian.
Can you pls elaborate a little bit on my questions 2, 3 and 4 in my previous post above?

re question 2 - (not linking files that were not in SourceFolder subfolders but were directly in SourceFolder) - i cannot seem to get anything out of it because out of description of mindepth and maxdepth, setting the line to:

Code: Select all

CreateTheLinks 'TRUE' 0 0 "$DestFolder" "${SourceFolders[@]}"

where these parameters are both 0, it should work and link these files (not folders) in SourceFolder, but it does not :( Am i getting or doing something wrong?

re question 3 - does it work for you - when you create a new folder in Sourcefolder - does it automatically show in DestFolder (if not running the script once again)? Because it does not work for me, but I have not changed anything in your script (except for what I explained before)

re question 4 - i don't think this is smth that can be fixed with tampering around this CreateTheLinks line and its parameters. Rather, it would need smth like - if a subfolder copied (linked) from first SourceFolder exists when the folder with the same name is to be copied (linked) from the second SourceFolder, copy (link) the contents of this subfolder of second Sourcefolder into the root of this existing folder of first Sourcefolder already copied (linked); rather than create a second subfolder under the first one! Do you get what I mean? If not, I can try to make some screenshots of the structure.

As to these things above, I'm afraid, I'd still need your help, as I can experiment with CreateTheLinks string, but I'm afraid I'm no use to writing even a simple code in Linux :( Will you help, pls?
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Using symlinks with the NTV550

Post by Ian »

Hi bruuss, I do apologise, I wasn't ignoring your questions, just forgot to answer them :oops:

Re question 2. I'll try and replicate this here.

Re question 3. The script should be run regularly (eg. via cron) so additions/deletions etc are kept up to date. Think of the script as like taking a snapshot of your content. As you change the content you need to update the snapshot.

Re question 4. I don't have duplicate folder names on my server so didn't think of coding for it. Let me have a play and come up with a solution if I can.

Bear with me......

Ian.
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

thanks Ian, I will wait for your solution.

meanwhile, i found out strange thing - as per your script - it creates symlinks not only in DestFolder, but also in SourceFolder :crazy: - i mean, i found out i get symlinks there and there. This needs to be fixed somehow, as symlinks in SourceFolders are not necessary. Don't you get such situation? Why does it happen?
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Using symlinks with the NTV550

Post by Ian »

Hi there,

OK, I've been having a fiddle and I think your problems stem from your foldernames having a ! in them. The ! is a special character and it's possible your OS is handling them different to mine. As a test could you try the script on folders without the ! in them and report back please?

Many thanks,

Ian.
bruuss
Member
Member
Posts: 10
Joined: August 19th, 2011, 2:25 pm

Re: Using symlinks with the NTV550

Post by bruuss »

ok. I tested with folder names without '!' character in them.
I don't think that is the case - I found out that where two sourcefolders had the same folders (with exactly the same names) the last mentioned problem persisted - 1) the script creates symlinks both in DestFolder and SourceFolder for the folders that have these exactly same names and 2) it puts one folder with the same name under another folder with the same name (opposed to merging the contents) - both in DestFolder and SourceFolder

Previous problem also persist:
- single files that are in the specified SourceFolders are not linked (put in the symlinks folder)

Even if there is problem with folders with '!' character in the name, I didn't recognize it this time (and it still would not be a solution to rename them, as I have named them so on purpose). There was problem with '!' character regarding to find strings (see my posts above). If you can fix your script so that it works with '!' character folder names normally, that would be great, as I had to replace that string as you know.

Waiting for any solution to the problems above from your side, Ian. Thank you.
Post Reply