如何更改登录外壳上显示的内容?


23

我越来越熟悉通过提示符(.bashrc)调整外壳中的内容的方式,但是现在我试图更改首次登录时显示的初始内容。在我的EC2实例上,这就是我看到的内容我登录:

         __|  __|_  )  Fedora 8
         _|  (     /    32-bit
        ___|\___|___|


  Welcome to: 

    Wowza Media Server 2 for Amazon EC2

      Version: 2.0.0.08

在我的家用Mint计算机上,这是我登录时看到的内容:

Welcome to Linux Mint 11 Katya (GNU/Linux 2.6.38-8-generic x86_64)

Welcome to Linux Mint
* Documentation:  http://www.linuxmint.com

Last login: Tue Jun 21 17:44:05 2011

在哪里定义?如何调整某些疯狂的ASCII艺术动作

Answers:


31

登录提示之前显示的文本存储在其中/etc/issue(有一个相关文件,/etc/motd在用户登录后,启动外壳程序之前显示)。这只是一个普通的文本文件,但它接受一堆转义序列:

  • \b -当前行的波特率。
  • \d - 当前日期。
  • \s -系统名称,操作系统的名称。
  • \l -当前tty行的名称。
  • \m-机器的架构标识符,例如 i486
  • \n -计算机的节点名,也称为主机名。
  • \o -机器的域名。
  • \r-操作系统的发行版号,例如 1.1.9。
  • \t - 当前时间。
  • \u -当前登录的用户数。
  • \U -字符串“ 1 user”或“ users”,其中是当前登录的用户数。
  • \v-操作系统版本,例如 建造日期等

在我的机器上,我有:

这是\ n(\ s \ m \ r)\ t \ l

呈现为:

这是etudes-1(Linux x86_64 2.6.39-gentoo)17:43:10 tty1


6

该文件/etc/issue/etc/issue.net是登录程序显示的文件。您可以在其中添加特殊的扩展字符,如其他答案所述。但是您可能还想尝试linux_logo程序。它可以为您生成非常好的ASCII艺术品问题文件。


4

用户显然是在询问登录后显示的消息,在输入登录名和密码之前,所有“ / etc / issue”都会显示出来,因此不在主题之列。

“登录外壳”步骤为:

  1. 显示“ / etc / issue”中包含的消息
  2. 询问用户并通过
  3. 显示每日消息来自:

    / etc / motd

    /etc/update-motd.d

  4. 启动/ etc / profile和〜/ .bash_profile

NB .bashrc是针对非登录外壳执行的

@Naftuli Kay将您的ASCII艺术添加到/ etc / motd中,或者将脚本添加到/etc/update-motd.d或/ etc / profile中,以实现用户独立打印,或〜/ .bash_profile中,以用于单用户打印


3

Ask Ubuntu

Ubuntu启动画面

检查上面的“ 询问Ubuntu”链接以获取评论以及其他用户的新答案。

now bash脚本

繁重的工作是显示以下内容的启动组件:

$ now

Weather report: Edmonton               March 2018            ┌────────────────────────────┐
                                  Su Mo Tu We Th Fr Sa          ┏━┓╺┓  ┏━┓┏━┓   ┏━┓┏┳┓   
     \   /     Sunny                           1  2  3          ┃┃┃  ╹┏━┛┗━┫   ┣━┛┃┃┃   
      .-.      -23--14 °C          4  5  6  7  8  9 10          ┗━┛╺┻╸╹┗━╸┗━┛         
    (   )     22 km/h          11 12 13 14 15 16 17       └────────────────────────────┘
      `-’      14 km              18 19 20 21 22 23 24  
     /   \     0.9 mm             25 26 27 28 29 30 31  

是的,在埃德蒙顿,确实是-14,感觉像-23。这是度过悠闲周末的美好时光,让他们可以玩新到的古墓丽影2013!也许重新整理一下简历即可搬到温哥华或蒙特利尔...

这是代码:

#!/bin/bash

# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Mar 30, 2018.

# NOTE: To display all available toilet fonts use this one-liner:
#       for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

#--------- WEATHER ----------------------------------------------------------

# Current weather, already in color so no need to override
echo " "
# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^

echo " "
echo " "                # Pad with blank lines for calendar & time to fit

#--------- DATE -------------------------------------------------------------

# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
#        36=cyan, 37=white

tput sc                 # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done

# Depending on length of your city name and country name you will:
#   1. Comment out next three lines of code. Uncomment fourth code line.
#   2. Change subtraction value and set number of print spaces to match
#      subtraction value. Then place comment on fourth code line.

Column=$(($DateColumn - 10))
tput cuf $Column        # Move x column number
printf "          "     # Blank out ", country" with x spaces
#tput cuf $DateColumn    # Position to column 27 for date display


# -h needed to turn off formating: /ubuntu/1013954/bash-substring-stringoffsetlength-error/1013960#1013960
cal -h > /tmp/terminal

CalLineCnt=1
Today=$(date +"%d")
# Prefix with space when length < 2
if [[ ${#Today} < 2 ]] ; then
    Today=" "$Today
fi
printf "\033[32m"   # color green -- see list above.

while IFS= read -r Cal; do
    printf "$Cal"
    if [[ $CalLineCnt > 2 ]] ; then
        # See if today is on current line & invert background
        tput cub 22
        for (( j=0 ; j <= 18 ; j += 3 )) ; do
            Test=${Cal:$j:2}            # Current day on calendar line
            if [[ "$Test" == "$Today" ]] ; then
                printf "\033[7m"        # Reverse: [ 7 m
                printf "$Today"
                printf "\033[0m"        # Normal: [ 0 m
                printf "\033[32m"       # color green -- see list above.
                tput cuf 1
            else
                tput cuf 3
            fi
        done
    fi

    tput cud1               # Down one line
    tput cuf $DateColumn    # Move 27 columns right
    CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal

printf "\033[00m"           # color -- bright white (default)
echo ""

tput rc                     # Restore saved cursor position.

#-------- TIME --------------------------------------------------------------

tput sc                 # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf $TimeColumn    # Move 49 columns right

# Do we have the toilet package?
if hash toilet 2>/dev/null; then
    echo " "$(date +"%I:%M %P")" " | \
        toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
    echo $(date +"%I:%M %P") | figlet > /tmp/terminal
# else use standard font
else
    echo $(date +"%I:%M %P") > /tmp/terminal
fi

while IFS= read -r Time; do
    printf "\033[01;36m"    # color cyan
    printf "$Time"
    tput cud1               # Up one line
    tput cuf $TimeColumn    # Move 49 columns right
done < /tmp/terminal

tput rc                     # Restore saved cursor position.

exit 0

先决条件

为了显示时间,您需要安装toilet

sudo apt install toilet

对于另一个花哨的时间显示(但不太花哨),请安装figlet

sudo apt install figlet

否则,时间将以“正常”字体显示。

天气

天气由curl wttr.in/cityname?0命令提供。在您的终端中使用:curl wttr.in/:help有关其他详细信息。

天气:更改城市名称

您需要修改此部分代码,然后更改Edmonton为您的城市名称:

# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^

Unicode支持城市名称,例如/Москва(Moscow)。支持机场字母,例如YEG埃德蒙顿。

天气:删除国家名称

当终端设置为92个字符宽时,天气显示为“加拿大埃德蒙顿”。我喜欢的时间太长了:

天气与country.png

更糟糕的是,将终端设置为默认80个字符宽时:

天气国家名称80 chars.png

为了解决该问题,在屏幕上使用以下代码将“,Countryname”空白:

# Depending on length of your city name and country name you will:
#   1. Comment out next three lines of code. Uncomment fourth code line.
#   2. Change subtraction value and set number of print spaces to match
#      subtraction value. Then place comment on fourth code line.
Column=$(($DateColumn - 10))
tput cuf $Column        # Move x column number
printf "          "     # Blank out ", country" with x spaces
#tput cuf $DateColumn    # Position to column 27 for date display

如果您需要脚本的这一部分的帮助,请在下面发表评论以寻求帮助。

终端屏幕宽度调整

通过更改以下内容,将间距调整为终端屏幕的宽度:

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

将它们捆绑在一起 ~/.bashrc

编辑~/.bashrc文件并将这些行添加到底部:

# Splash Calendar and time
now

# ASCII Linux distribution display
screenfetch

保存`〜/ .bashrc“文件更改。

要显示Ubuntu信息,您需要screenfetch

sudo apt install screenfetch

有类似的显示包,screenfetch所以货比三家!

如果要在命令提示符之间使用“──────────分隔行,请更改以下行:

if [ "$color_prompt" = yes ]; then
    PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

注意分隔线的长度与screenfetch输出的宽度一致。在这种情况下,它的宽度为92个字符,并且相应gnome-terminal地设置了首选项。


1

您还可以将ssh守护程序配置为在登录期间显示消息。在sshd_config文件中使用Banner指令指定要显示的文件:

Banner /etc/ssh/ssh_banner

文件名可以是任何文件,但是为了清楚起见,我将其与sshd_config文件一起保留在/ etc / ssh中。


0

一个小脚本,用于在debian主机的/etc/rc.local中生成具有网络地址的/ etc / issue。

/bin/echo "This is \n(\s \m \r) \t \l">/etc/issue
/bin/sleep 10 # This is optional, sometimes OS need more time to get ip address while DHCP, otherwise maybe you will get nothing :(
/sbin/ip a| /bin/grep inet| /bin/grep -v -E "inet6|127.0.0.1"| /bin/sed "s/\s*//"|/bin/sed "s/\/24.*//" >>/etc/issue

更新:用“ ip -4 -br a”听起来就足够了,谢谢@Mathieu CAROFF!


man ip。使用-br开关。您可能还想使用该-4开关。您的命令可以缩短为ip -br a | sed -nE 's:^(\w+)\s+UP\s+([0-9.]+)/.*$:\1 \2:p'。更好的是使用hostname -I
Mathieu CAROFF

0

使用此ssh标语的重要提示:“日间突出显示”仅适用于“ ncal -bh> / tmp / terminal”,而不适用于cal -h。cal -h不起作用/不存在(Ubuntu 18.04)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.