Почему операция `chroot` приводит к ошибке: "bash: /root/.bashrc: Отказано в доступе"?

sed -e '
   s/::/\n/;s//\n/
   s/^\([^_]*\)_.*\n\(.*\)\n.*/\2[\1]/
   ;#  |--1---|      |-2-|
' ID.data

Поместите маркеры вокруг строки идентификатора и захватите часть перед первой _и замените всю строку этими значениями. Выход:

TRINITY_DN120587_c0_g1_i1[ID1]

Пояснение

              ID1_TRINITY_DN120587_c0_g1::TRINITY_DN120587_c0_g1_i1::g.8298::m.8298
              |-|                         |-----------------------|

Вы сказали, что хотите извлечь идентификатор, который находится между 1-м и 2-м вхождением::

Шаг -1 :Поместите маркер (обычно \n )вокруг интересующей области:

       s/::/\n/;s//\n/

   This is how the pattern space looks after the above tranformation

              ID1_TRINITY_DN120587_c0_g1\nTRINITY_DN120587_c0_g1_i1\ng.8298::m.8298

Шаг -2 :Извлеките идентификатор, который находится между двумя \ns, а также строку для слева от 1-го вхождения_

                    s/^\([^_]*\)_.*\n\(.*\)\n.*/\2[\1]/
                    ;#  |------|      |---|
                    ;#     \1           \2

   [^_]       => matches any char but an underscore

   [^_]*      => matches 0 or more non underscore char(s)

   \([^_]*\)  => store what was matched into a memory, recallable as \1

   ^\([^_]*\) => anchor your matching from the start of the string

  .*\n       => go upto to the rightmost \n you can see in the string

   \n\(.*\)\n => Ooops!! we see another \n, hence we need to backtrack to
                 the previous \n position and from there start moving right again
                 and stop at the rightmost \n. Whatever is between these positions
                 is the string ID and is recallable as \2. Since the \ns fall outside
                 the \(...\), hence they wouldn't be stored in \2.

  .*         => This is a catchall that we stroll to the end of the string after
                 starting from the rightmost \n position and do nothing with it.

 So our regex engine has matched against the input string it was given in
 the pattern space and was able to store in two memory locations the data
 it was able to gather, viz.: \1 => stores the string portion which is in
 between the beginning of the pattern space and the 1st occurrence of the
 underscore.

 \2 => store the string portion which is in between the 1st and 2nd
       occurrences of :: in the pattern space.

                      \1 = ID1
                      \2 = TRINITY_DN120587_c0_g1_i1

 Now comes the replacement part. Remember that the regex engine was able to scan
 the whole of pattern space from beginning till end, hence the replacement
 will effect the whole of the pattern space.

 \2[\1] => We replace the matched portion of the pattern space (in our case it
           happens to be the entire string) with what has been stored in
           the memory \2 literal [ memory \1 literal ]
           leading to what we see below:

                  TRINITY_DN120587_c0_g1_i1[ID1]

In other words, you have just managed to turn the pattern space from:

              ID1_TRINITY_DN120587_c0_g1::TRINITY_DN120587_c0_g1_i1::g.8298::m.8298

into the following:

                  TRINITY_DN120587_c0_g1_i1[ID1]
2
23.09.2019, 12:37
1 ответ

Передача --userspecв chroot— это не то же самое, что запуск su - userвнутри среды chroot; то есть домашний каталог по-прежнему является корневым, то есть /root, поэтому bashпытается прочитать /root/.bashrc, что не разрешено для пользователей, не являющихся -root.

Вторая проблема, вероятно, связана с тем, что вы не включили все необходимые общие библиотеки в среду chroot. Из информационного документа chroot:

If you want to use a dynamically linked executable, say ‘bash’, then first run ‘ldd bash’ to see what shared objects it needs. Then, in addition to copying the actual binary, also copy the listed files to the required positions under your intended new root directory. Finally, if the executable requires any other files (e.g., data, state, device files), copy them into place, too.

2
27.01.2020, 22:08

Теги

Похожие вопросы