![我收到 motd 标头语法错误,需要帮助启用 motd](https://linux22.com/image/912916/%E6%88%91%E6%94%B6%E5%88%B0%20motd%20%E6%A0%87%E5%A4%B4%E8%AF%AD%E6%B3%95%E9%94%99%E8%AF%AF%EF%BC%8C%E9%9C%80%E8%A6%81%E5%B8%AE%E5%8A%A9%E5%90%AF%E7%94%A8%20motd.png)
我正在尝试修复我的 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