我正在嘗試修復我的 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