-
-
----2016-04-05 07:30:37
linux
----, 2016-04-05 07:30:37

Bulk editing of symlinks in Debian - HOW?

Salute to all! There is a dedicated web server on Debian (nginx + apache2), several sites were transferred to it from another server.
The user account on the old one was user1, on the new one it was user2.
The problem is this: on a new server in the /var/www/user2/data/ folder. . in different subdirectories there are many symlinks leading to images (I struggled with duplicate images)... But the path for symlinks is /var/www/ user1 /..
How to make a mass change of symlinks so that all the pictures on the site work? At the moment - they are not displayed (403- Forbidden)
The method with commenting this line in nginx.conf and creating a symlink /var/www/user1 --> /var/www/user2 - tried .. does not help
(#disable_symlinks if_not_owner from =$root_path;)
Maybe there are other ways?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Andrey Mikhalev, 2016-04-05
@Endru9

here either change the path as on the old server, or make a script.
something like this:

#!/bin/bash
for i in $(find -type l -exec ls -l {} \; | awk '{ print $9 $10 $11 }')
        do
#b - это сам симлинк
#e - это файл на который ссылаются.
        b=`echo $i | awk -F '->' '{ print $1}'`
        e=`echo $i | awk -F '->' '{ print $2}'`
        echo $b
        echo $e
        e=`echo $e |sed 's/user1/user2/g'`
        echo $e
        #rm $b #удаляем симлинк и делаем новый.
        #новый симлинк (выполнять с опаской, лучше проверить и перепроверить.
        #снять комментарий если все будет работать как нужно
        #ln -s $e $b
done

Naturally, I did not check it, and sketched it out in a couple of minutes, but I think this will be an impetus for solving the problem.

Y
Yuri Chudnovsky, 2016-04-05
@Frankenstine

Maybe it will be easier for you to just place the files in the old path? ;)
Well, "on the forehead" the problem is solved by creating a bash-script that sorts through symlinks and for those that are broken (do not lead to a file) make a new symlink (correct), and delete the broken one.

-
----, 2016-04-05
@stalkerxxl

Arranging several thousand files is not an option =) I
also tend to write a bash script ... But alas, no experience and the concept of "which side to approach" ... =-(

A
Alexey Yamschikov, 2016-04-05
@mobilesfinks

make a symlink :)
ln -s /var/www/user2 /var/www/user1

A
abcd0x00, 2016-04-06
@abcd0x00

Make a script that remakes one link. You just give him the address of the link, and he turns it into the correct link. As you do, run the search for links command, where for each link found, this script is called.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question