我收到 motd 标头语法错误,需要帮助启用 motd

我收到 motd 标头语法错误,需要帮助启用 motd

我正在尝试修复我的 ubuntu 服务器上的 motd 脚本,/etc/update-motd.d/00-header /etc/update-motd.d/01-sysinfo /etc/update-motd.d/02-footer 因为出于某些奇怪的原因,我一直收到这个奇怪的语法错误,它显示“ line 31: syntax error: unexpected end of file”,但它指向一个没有代码的空白处,这真是令人困惑。

另一个问题是,每当我输入 systemctl status motd 时,屏幕上都会出现这个。

Unit motd.service could not be found.

我在屏蔽过程中遇到了问题,因此我使用了此链接中的解决方案systemctl,如何揭露

我已经与这个问题斗争了一段时间,但我正在努力解决这个问题,因此非常感谢您的帮助。

该文件的内容位于本文下方。

#!/bin/sh
#
#    00-header - create the header of the MOTD Copyright (c) 2013 Nick Charlton Copyright (c)
#    2009-2010 Canonical Ltd.
#
#    Authors: Nick Charlton <[email protected]>
#             Dustin Kirkland <[email protected]>
#
#    This program is free software; you can redistribute it and/or modify it under the terms
#    of the GNU General Public License as published by the Free Software Foundation; either
#    version 2 of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along with this
#    program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
#    Floor, Boston, MA 02110-1301 USA.

[ -r /etc/lsb-release ] && . /etc/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
        # Fall back to using the very slow lsb_release utility
        DISTRIB_DESCRIPTION=$(lsb_release -s -d) fi

figlet $(Ourserver) printf "\n"
printf "Welcome to %s (%s).n" "$DISTRIB_DESCRIPTION" "$(uname -r)" printf "\n"

答案1

出现“ line 31: syntax error: unexpected end of file”是因为“成对”字符的数量为奇数。所谓“成对”字符,我指的是必须与匹配字符一起出现的字符,可能中间还会出现其他字符。例如,"'([{等。计算一下引号:

files="/etc/update-motd.d/00-header /etc/update-motd.d/01-sysinfo /etc/update-motd.d/02-footer"
grep --color=always -E "\"|'|\(|\[|\{|\}|\]|\)" $files

答案2

错误似乎起源于第 25 行:

25          DISTRIB_DESCRIPTION=$(lsb_release -s -d) fi

在 -之前需要有一个分隔符,fi可以是 a;或换行符(我建议使用后者,因为它可以保留正确的缩进)。因此

23  if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
24          # Fall back to using the very slow lsb_release utility
25          DISTRIB_DESCRIPTION=$(lsb_release -s -d)
26  fi

相关内容