与你分享
互联网的方方面面

CentOS 7系统配置动态motd教程

在 CentOS 7 中,可以通过修改 /etc/profile.d 目录下的脚本来实现动态 motd(Message of the Day)。以下是操作步骤:

1、在 /etc/profile.d 目录下创建一个新的脚本文件,例如 motd.sh,使用 root 用户权限进行操作:

vim /etc/profile.d/motd.sh

2、在打开的文件中,添加以下内容:

#!/bin/bash
# Generate dynamic motd

# Get system information
HOSTNAME=$(hostname)
KERNEL=$(uname -r)
UPTIME=$(uptime -p)
LOAD=$(uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print $3 }')

# Clear existing motd
cat /dev/null > /etc/motd

# Set the new motd content
echo "Welcome to ${HOSTNAME}!"
echo
echo "System information:"
echo "  - Kernel: ${KERNEL}"
echo "  - Uptime: ${UPTIME}"
echo "  - Load average: ${LOAD}"
echo

3、保存并关闭文件。

4、授予脚本执行权限:

chmod +x /etc/profile.d/motd.sh

当登录到系统时,/etc/profile.d 目录中的脚本会自动执行,生成新的 motd。重启或注销并重新登录到系统,应该能够看到更新后的动态 motd 信息。

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《CentOS 7系统配置动态motd教程》
文章链接:https://wph.im/215.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

相关推荐

  • 暂无文章