Как скрипты оболочки в файле /etc/profile.d/ влияют на / etc / profile

Я написал сценарий оболочки и поместил его в /etc/profile.d/.

Скрипт содержит следующее:

if [ ] # Boolean condition is in these brackets. then shutdown -P 23:00

Итак, когда я вхожу в систему, я получаю сообщение который начинается:

Error found when loading /etc/profile: Shutdown scheduled for ... 23:00:00 PDT, use 'shutdown -c' to cancel. As a result the session will not be configured correctly. You should fix the problem as soon as feasible.

Это странно для меня, потому что я не внес никаких изменений в /etc/profile.

Мой вопрос из этого имеет несколько частей:

Я должен внести изменения в /etc/profile?

Или проблема, которую я использую shutdown в /etc/profile.d/?

1
задан 20 August 2017 в 06:56

2 ответа

В /etc/profile мы видим:

if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi

То есть сценарии, называемые *.sh в /etc/profile.d, будут выполняться всякий раз, когда выполняется /etc/profile.

] Когда выполняется /etc/profile? man bash (или Online man page показывает:

When bash is invoked as an interactive login shell, or as a non- interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

и:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior.

Все это означает, что каждый раз, когда вы вызываете /etc/profile (Выше показано, когда bash делает ли ваш ~/.bashrc?) сценарии будут запущены.

В ваших вторых (и последующих) вызовах /etc/profile, shutdown видит, что активен другой shutdown, и жалобы.

Вы могли бы поставить shutdown -c перед shutdown -P 23:00 в свой скрипт, чтобы заменить старый shutdown на новый shutdown.

2
ответ дан 18 July 2018 в 08:14

В /etc/profile мы видим:

if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi

То есть сценарии, называемые *.sh в /etc/profile.d, будут выполняться всякий раз, когда выполняется /etc/profile.

] Когда выполняется /etc/profile? man bash (или Online man page показывает:

When bash is invoked as an interactive login shell, or as a non- interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

и:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior.

Все это означает, что каждый раз, когда вы вызываете /etc/profile (Выше показано, когда bash делает ли ваш ~/.bashrc?) сценарии будут запущены.

В ваших вторых (и последующих) вызовах /etc/profile, shutdown видит, что активен другой shutdown, и жалобы.

Вы могли бы поставить shutdown -c перед shutdown -P 23:00 в свой скрипт, чтобы заменить старый shutdown на новый shutdown.

2
ответ дан 24 July 2018 в 19:02
  • 1
    О да, спасибо за помощь. В этом есть смысл. Я должен был подумать о том, чтобы использовать страницы руководства для bash. Я попробую ваше предложение – hwdbc 20 August 2017 в 07:06
  • 2
    После использования вашей рекомендации сообщение об ошибке остается неизменным. Кажется, мне придется сделать еще несколько исследований – hwdbc 20 August 2017 в 07:25

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

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