Как делают сценарии оболочки в/etc/profiled.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

1 ответ

Взгляд на /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 (или шоу страницы справочника Онлайн:

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
ответ дан 20 August 2017 в 16:56

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

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