【发布时间】:2020-10-12 11:41:16
【问题描述】:
我正在使用带有基于 Debian 的发行版的 Raspberry Pi(我认为它称为 Raspbian)。我将一个名为10-pi 的文件放入/etc/update-motd.d 目录并使其可执行。当我自己运行可执行文件(bash)时,它向我展示了一个带有颜色的漂亮 MOTD。然而,当我使用 ssh 登录我的 Pi 时,我看到了正确的 MOTD,但它以白色显示所有内容。有人知道为什么会这样吗?
这是我的10-pi 文件:
#!/bin/bash
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
read one five fifteen rest < /proc/loadavg
echo "$(tput setaf 2)
.~~. .~~. `date +"%A, %e %B %Y, %r"`
'. \ ' ' / .' `uname -srmo`$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. : Uptime.............: ${UPTIME}
~ ( ) ( ) ~ Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
~ .~ ( ) ~. ~ Running Processes..: `ps ax | wc -l | tr -d " "`
( : '~' : ) IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail`
'~ .~~~. ~' Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=EUR|UK|UK001|NAILSEA|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2\3, \1/p'`
'~'
$(tput sgr0)"
这是我自己执行文件时的样子: Output when executed manually
【问题讨论】:
-
您可能会从以下地址获得专家帮助:raspberrypi.stackexchange.com
-
可能您的
ssh终端会话不支持您尝试使用的控制代码曲目。当您没有得到彩色输出时,$TERM的值是多少? -
上面的链接没有回答这个问题。这是放置在 /etc/update-motd.d 中的脚本,而不仅仅是放置在 /etc/motd 中的消息
-
我在脚本末尾添加了一个 echo $TERM 行。如果我自己登录,我总是得到“xterm-256color”,但是当它作为 motd 执行时,它显示“哑”
标签: linux bash raspberry-pi raspbian debian-based