Вариант использования, где имена файлов сценариев имеют начальные числа для определения порядка выполнения

Я ищу документацию или пример использования, где в Linux есть каталог со сценариями оболочки, где каждое имя файла приводится с номером, а файлы запускаются в определенном порядке. Как называется это соглашение и где оно используется?

Например:

0001-motd.sh
0002-proxy.sh
0300-ssh.sh

Я знаю, что видел это раньше, просто не уверен, где или как оно называется.

9
задан 22 December 2017 в 22:15

2 ответа

Похоже, вы имеете в виду run-parts

NAME
       run-parts - run scripts or programs in a directory

SYNOPSIS
       run-parts  [--test]  [--verbose] [--report] [--lsbsysinit] [--regex=RE]
       [--umask=umask] [--arg=argument] [--exit-on-error] [--help] [--version]
       [--list] [--reverse] [--] DIRECTORY

       run-parts -V

DESCRIPTION
       run-parts  runs  all  the  executable  files  named  within constraints
       described below, found in directory directory.  Other files and  direc‐
       tories are silently ignored.

       If neither the --lsbsysinit option nor the --regex option is given then
       the names must consist entirely of ASCII upper- and lower-case letters,
       ASCII digits, ASCII underscores, and ASCII minus-hyphens.

       If  the  --lsbsysinit  option  is given, then the names must not end in
       .dpkg-old  or .dpkg-dist or .dpkg-new or .dpkg-tmp, and must belong  to
       one  or more of the following namespaces: the LANANA-assigned namespace
       (^[a-z0-9]+$);   the   LSB   hierarchical   and   reserved   namespaces
       (^_?([a-z0-9_.]+-)+[a-z0-9]+$);  and  the  Debian cron script namespace
       (^[a-zA-Z0-9_-]+$).

       If the --regex option  is  given,  the  names  must  match  the  custom
       extended regular expression specified as that option's argument.

       Files  are  run  in  the  lexical  sort order (according to the C/POSIX
       locale character collation rules) of their names unless  the  --reverse
       option is given, in which case they are run in the opposite order.
12
ответ дан 22 December 2017 в 22:15

Я не знаю, подойдет ли этот метод / хак для вашего случая. Но я думаю, что это сработает, если я вас правильно понял.

[feddy@localhost ~]$ mkdir test
[feddy@localhost ~]$ cd test
[feddy@localhost test]$ ls
[feddy@localhost test]$ vi 0001-ko.sh
[feddy@localhost test]$ cp 0001-ko.sh 0002-ko.sh
[feddy@localhost test]$ cp 0001-ko.sh 0004-ko.sh
[feddy@localhost test]$ cp 0001-ko.sh 0005-ko file.sh
[feddy@localhost test]$ cp 0001-ko.sh 0008-ko.sh
[feddy@localhost test]$ ls
0001-ko.sh  0002-ko.sh  0004-ko.sh  0005-ko file.sh  0008-ko.sh

[feddy@localhost test]$ for i in *
> do
> bash "$i"
> done
file 0001-ko.sh
file 0002-ko.sh
file 0004-ko.sh
file 0005-ko file.sh
file 0008-ko.sh
[feddy@localhost test]$

ИЛИ

$ find . -iname "*.sh"|while read f; do bash "$f"; done
file ./0001-ko1.sh
file ./0002-ko1.sh
file ./0005-ko1 file.sh
file ./0005-ko1.sh

Вы можете создать сценарий и использовать его для выполнения сценариев по порядку (в соответствии с числами, включенными в имя файла, например, xxxx-abcdef) в любая папка.

Пожалуйста, поправьте меня, если я вас неправильно понял.

-1
ответ дан 22 December 2017 в 22:15

Другие вопросы по тегам:

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