Расшифровать раздел LUKS скриптом в правилах udev

Использование GNU sed

sed -e '/g[0-9]\+\(\s*NA\s*\)\+$/d' filename

Краткое пояснение:

g[0-9]\+\(\s*NA\s*\)\+$— это регулярное выражение, соответствующее g, за которым следует хотя бы одна цифра, затем любое количество NAс необязательными пробелами до конца строки.

sed -e '/<regex>/d'удаляет все строки, соответствующие<regex>

Более стандартное регулярное выражение с тем же значением будет:

sed -Ee '/g[0-9]+([[:space:]]*NA[[:space:]]*)+$/d' filename
1
21.11.2020, 14:43
1 ответ

Наконец-то я нашел проблему. С RUN вы не можете выполнять длинные программы/скрипты. И решение состоит в том, чтобы создать службу, которая запускает ваш скрипт, и использовать правило SYSTEMD _WANTS с вашей службой.

От ман удев:

RUN{тип} Добавить программу в список программ для выполнения после обработки всех правил для конкретного события в зависимости от «типа»:

   "program"
       Execute an external program specified as the assigned value. If no absolute path is given, the program is expected to live in /lib/udev; otherwise, the absolute path must be specified.          

       This is the default if no type is specified.

   "builtin"
       As program, but use one of the built-in programs rather than an external one.

   The program name and following arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.                                                                         

   This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device.                        

   Starting daemons or other long-running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.            

   Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules, due to the default sandbox that is enforced on systemd-udevd.service.   

Решение:

Создайте службу в /etc/systemd/system/myservice.service>

[Unit]
Description=Auto backup

[Service]
ExecStart=/home/manu/Sysadmin/auto-backup.sh

И изменить правило udev:

ACTION=="add", KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{size}=="1048576000", ENV{SYSTEMD_WANTS}="myservice.service"
1
18.03.2021, 22:48

Теги

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