ubuntu欢迎界面ip显示错误

Ubuntu 的欢迎界面,也称为 **MOTD (Message Of The Day)**,是在用户登录系统后显示的信息。

Ubuntu 的 MOTD 配置方式与其他一些 Linux 发行版有所不同,它使用 /etc/update-motd.d/ 目录下的脚本来动态生成 MOTD 信息。

env

  • ubuntu-22.04.5 lts

解决

1.登录后欢迎界面

3c80af466384f103c179c2b00b3d68c5.png

2.分析过程

root@gaga:~# ll /etc/update-motd.d/    # motd动态配置
total 60
drwxr-xr-x  2 root root 4096 Jan 17 05:35 ./
drwxr-xr-x 96 root root 4096 Jan 17 05:35 ../
-rwxr-xr-x  1 root root 1220 Oct 15  2021 00-header*
-rwxr-xr-x  1 root root 1151 Sep 10 11:16 10-help-text*
lrwxrwxrwx  1 root root   46 Sep 11 14:24 50-landscape-sysinfo ->  # sysinfo配置
/usr/share/landscape/landscape-sysinfo.wrapper*
-rwxr-xr-x  1 root root 5023 Oct 15  2021 50-motd-news*
-rwxr-xr-x  1 root root   84 May 17  2023 85-fwupd*
-rwxr-xr-x  1 root root  218 Feb 16  2024 90-updates-available*
-rwxr-xr-x  1 root root  296 Jun 17  2024 91-contract-ua-esm-status*
-rwxr-xr-x  1 root root  558 Jan  9  2023 91-release-upgrade*
-rwxr-xr-x  1 root root  165 Feb 19  2021 92-unattended-upgrades*
-rwxr-xr-x  1 root root  379 Feb 22  2024 95-hwe-eol*
-rwxr-xr-x  1 root root  111 Aug 17  2020 97-overlayroot*
-rwxr-xr-x  1 root root  142 Feb 16  2024 98-fsck-at-reboot*
-rwxr-xr-x  1 root root  144 Feb 16  2024 98-reboot-required*


root@gaga:~# cat /etc/update-motd.d/50-landscape-sysinfo 
#!/bin/sh

# don't try refresh this more than once per minute
# Due to cpu consumption and login delays (LP: #1893716)
CACHE="/var/lib/landscape/landscape-sysinfo.cache"
HAS_CACHE="FALSE"
CACHE_NEEDS_UPDATE="FALSE"

# 读取到缓存则读取
[ -r "$CACHE" ] && HAS_CACHE="TRUE"
[ -z "$(find "$CACHE" -newermt 'now-1 minutes' 2> /dev/null)" ] && CACHE_NEEDS_UPDATE="TRUE"

if [ "$HAS_CACHE" = "TRUE" ] && [ "$CACHE_NEEDS_UPDATE" = "FALSE" ]; then
    cat "$CACHE"
else
    SYSINFO=""

    # pam_motd does not carry the environment
    [ -f /etc/default/locale ] && . /etc/default/locale
    export LANG
    CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null)
    [ "$CORES" -eq "0" ] && CORES=1
    THRESHOLD="${CORES:-1}.0"

    if [ $(echo "`cut -f1 -d ' ' /proc/loadavg` < $THRESHOLD" | bc) -eq 1 ]; then
        SYSINFO=$(printf "\n System information as of %s\n\n%s\n" \
            "$(/bin/date)" \
            "$(/usr/bin/landscape-sysinfo)")
        echo "$SYSINFO" 2>/dev/null >"$CACHE" || true
        chmod 0644 "$CACHE" 2>/dev/null || true
....

3.删除sysinfo缓存信息

/var/lib/landscape/landscape-sysinfo.cache

系统信息:
/usr/bin/landscape-sysinfo

885177e62c6dfab4d79ff82c1307a0f9.png