Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all. I'm using CentOS 5.5 I am trying to write a script that will find recently created directories (touched within 30 days) and create a symbolic link to those ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2

    symlink script


    Hi all. I'm using CentOS 5.5

    I am trying to write a script that will find recently created directories (touched within 30 days) and create a symbolic link to those directories in another folder. Here is the script:


    Code:
    #!/bin/sh
    
    cd /home/chris/Documents/;
    
    rm -rf ./recent_files/*;
    
    find ./ -maxdepth 1 -mindepth 1 \
            -type d -mtime -30 ! -name recent_files \
            -exec ln -s {} ./recent_files/ \;
    I have the script running once a night and removing the contents of the folder (rm -rf ./recent_files/*) in order to clear any files out and renew the symlinks. This will remove all files and the ones that aren't 30 days will not be symbolically linked when the -exec ln -s {}... command is run -- not sure if there is a better way to do this?

    Now to the question:
    Now with the above script, all the links are copied to the recent_files folder and can be seen through a shell but they are all broken. If i create the symbolic links in the current folder, they seem to work. e.g. if i do this:

    Code:
    find ./specific_file.mp3 \
    -exec ln -s {} ./specific_file_with_different_name.mp3 \;
    this seems to work. -- taking a file and creating a symlink with a different name in the same folder.

    So even doing this in a command line does not work. It copies the link into the correct folder, with the correct name, etc. but the symlink is broken:
    Code:
     ln -s test_file.avi recent_files/test_file.avi
    where 'recent_files' is a directory inside the current directory. This is not allowing me to create a symlink in another folder other than the current folder...

    all permissions are ok for this user on the recent_files folder, etc. -- Not sure if i am missing something with symlinks and copying them into different folders...

    Any suggestions?
    Thanks so much for any help!!

    - Chris

  2. #2
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2
    Figured it out....

    Thought absolute paths would do the trick (kinda)...
    So absolute paths work for symlinks, but those symlinks would not show up in my chrooted proftpd configuration. This is because the chroot moves the root folder of / to /~user (so the symlink paths were not correct according to proftpd)


    Here is what I ended up doing.

    It is a script that goes along with my proftpd server.

    Code:
    #!/bin/sh
    
    rm -rf ~/_____Recently__Added__Albums_____/*;
    cd ~/_____Recently__Added__Albums_____/;
    find ../ -maxdepth 1 -mindepth 1 \
            -type d -mtime -30 ! -name _____Recently__Added__Albums_____ \
            -exec ln -s {} ./ \;

    This works and also bypasses all the security issues with proftpd and being chrooted with SymLinks...

    to get the symlinks to actually show in proftpd I had to cd into the directory where I want the symlinks and create them from there (hence the ../ in the find command). It would not work to create the symlink from ~ into a subdirectory.


    hope this helps someone else.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •