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
update-motd.d scripts not running
提问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
For those on newer Ubuntu versions simply looking to update a static message, /etc/motd.tail
is 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 ssh
to remote into the machine.
对于那些在较新的 Ubuntu 版本上只想更新静态消息的人来说,/etc/motd.tail
现在/etc/motd
是(是的,您必须创建此文件),因此对于简单的静态更改,Ubuntu 版本之间的位置略有变化。使用ssh
远程进入机器时将显示此文件。
Use sudo vi /etc/motd
and 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 x1B
character).
接下来,使用vi
, 替换^[
为正确的“转义”字符(x1B
字符)。
- Within vi, press :
- Next type the following:
%s/\^\[/
(Do NOThit Enter) - Now type Ctrl+ vand then hit Esc
- Finally, type
/g
and 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 actualEsc
)/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 ESC
characters, used to add color to the terminal. :)
注意:尽管外观很奇怪,但蓝色^[
字符是完全有效的ESC
字符,用于为终端添加颜色。:)
If vi
is too tough to use, echo $'\e[1;37m' > myfile
can add the escape characters as well. Furthemore, gedit
can 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