bash update-motd.d 脚本未运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41088877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:31:22  来源:igfitidea点击:

update-motd.d scripts not running

bashubuntusshubuntu-14.04

提问by Paul Goggin

I have created a test script below to add to /etc/update-motd.d/05-lsb-release

我在下面创建了一个测试脚本来添加到 /etc/update-motd.d/05-lsb-release

#!/bin/sh
echo
lsb_release -a

but when i have rebooted the machine, restarted SSH and connected to it through SSH i am not seeing the changes applied

但是当我重新启动机器,重新启动 SSH 并通过 SSH 连接到它时,我没有看到应用的更改

Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-105-generic x86_64)

0 packages can be updated. 0 updates are security updates. 

Last login: Sun Dec 11 17:08:40 2016 from xxx.xxx.xxx.xxx
paul@ubuntu1404:~$

the output in /var/run/update-motd.dynamic is the same as above, however /var/run/update-motd.dynamic.new shows the correct information

/var/run/update-motd.dynamic 中的输出与上面相同,但是 /var/run/update-motd.dynamic.new 显示了正确的信息

Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-105-generic x86_64)

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty

0 packages can be updated.
0 updates are security updates.

how can i see the changes when i log in?

我如何在登录时看到更改?

I am running the latest updates to Ubuntu 14.04.5 LTS

我正在运行 Ubuntu 14.04.5 LTS 的最新更新

回答by reto

You might have an error in your motd script. Check it with:

您的 motd 脚本中可能有错误。检查它:

run-parts /etc/update-motd.d/ > /dev/null

Should this command report errors you need to fix them.

如果此命令报告错误,您需要修复它们。

回答by Jakuje

It is configured in the PAM. Have a look into the file /etc/pam.d/sshd. There is a line such as

它是在 PAM 中配置的。看看文件/etc/pam.d/sshd。有一条线,例如

session    optional     pam_motd.so noupdate

which prevents dynamic updates when logging in (your "dynamic" MoTD is quite static, so it does not make sense to update it with every login, isn't it?).

这会在登录时阻止动态更新(您的“动态”MoTD 是相当静态的,因此每次登录时都更新它是没有意义的,不是吗?)。

More described in the AskUbuntu.

AskUbuntu 中有更多描述。

回答by ThorSummoner

Test your motd like the (ubuntu? maybe debian too?) system does

像(ubuntu?也许是debian?)系统一样测试你的motd

/usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d

/usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d

(taken from this blog https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/)

(取自此博客https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/

in my case, lolcat was dying on utf8 chars because it was being launched with an ASCII as its language, fixed by prefixing the lolcal invocation with LANG=en_US.UTF-8 lolcat ...

就我而言,lolcat 在 utf8 字符上濒临死亡,因为它是使用 ASCII 作为其语言启动的,通过在 lolcal 调用前加上前缀来修复 LANG=en_US.UTF-8 lolcat ...

回答by tresf

enter image description here

在此处输入图片说明

For those on newer Ubuntu versions simply looking to update a static message, /etc/motd.tailis now /etc/motd(yes, you have to create this file), so for simple, static changes, the location has changed slightly between Ubuntu versions. This file will display when using sshto remote into the machine.

对于那些在较新的 Ubuntu 版本上只想更新静态消息的人来说,/etc/motd.tail现在/etc/motd是(是的,您必须创建此文件),因此对于简单的静态更改,Ubuntu 版本之间的位置略有变化。使用ssh远程进入机器时将显示此文件。

Use sudo vi /etc/motdand then paste this in...

使用sudo vi /etc/motd然后将其粘贴到...

 ^[[1;37m______ ______ ______ ______
|______|______|______|______|
| | ^[[1;31m____ ^[[1;33m     ^[[1;32m_  ^[[1;34m    ^[[1;36m     ^[[1;37m| |
| |^[[1;31m/ ___|^[[1;33m___ ^[[1;32m| | ^[[1;34m___  ^[[1;36m_ __^[[1;37m| |
| ^[[1;31m| |   ^[[1;33m/ _ \^[[1;32m| |^[[1;34m/ _ \^[[1;36m| '__|^[[1;37m |
| ^[[1;31m| |__^[[1;33m| (_) ^[[1;32m| ^[[1;34m| (_) ^[[1;36m| |  ^[[1;37m| |
| |^[[1;31m\____^[[1;33m\___/^[[1;32m|_|^[[1;34m\___/^[[1;36m|_|  ^[[1;37m| |
|_|____ ______ ______ ____|_|
|______|______|______|______|
^[[0m

Next, using vi, replace ^[with the proper "escape" character (the x1Bcharacter).

接下来,使用vi, 替换^[为正确的“转义”字符(x1B字符)。

  • Within vi, press :
  • Next type the following: %s/\^\[/(Do NOThit Enter)
  • Now type Ctrl+ vand then hit Esc
  • Finally, type /gand finally hit Enter.
  • If done properly the ^[changed from gray to blue. If not, hit uto undo.

    What is this all doing? Well...

    %s(search)
    /(first item)
    \^\[(escaped version of ^[)
    /(second item)
    (we use keyboard to insert actual Esc)
    /g(repeat for all occurrences)

  • 在 vi 中,按 :
  • 接下来键入以下内容:%s/\^\[/(做Enter
  • 现在输入Ctrl+v然后点击Esc
  • 最后,键入/g并点击Enter
  • 如果做得好,^[从灰色变为蓝色。如果没有,请点击u撤消。

    这一切在做什么?好...

    %s(search)
    /(first item)
    \^\[(escaped version of ^[)
    /(second item)
    (我们使用键盘插入实际的Esc)
    /g(重复所有出现的)

Note:Despite the cosmetic weirdness, the blue ^[characters are completely valid ESCcharacters, used to add color to the terminal. :)

注意:尽管外观很奇怪,但蓝色^[字符是完全有效的ESC字符,用于为终端添加颜色。:)

If viis too tough to use, echo $'\e[1;37m' > myfilecan add the escape characters as well. Furthemore, geditcan copy/paste these characters much better than vi|nano.

如果vi太难使用,echo $'\e[1;37m' > myfile也可以添加转义字符。此外,gedit可以比vi|nano.

For more terminal colors, please visit https://unix.stackexchange.com/a/174/190347

更多终端颜色请访问https://unix.stackexchange.com/a/174/190347