更改在 RHEL 6.4 中启动和停止服务时看到的状态消息的颜色和文本?

更改在 RHEL 6.4 中启动和停止服务时看到的状态消息的颜色和文本?

如何在启动或停止服务时更改消息的颜色和文本?

**在此输入图像描述**

答案1

对于 CentOS 6.10,以下文件包含 SETCOLOR_SUCCESS、SETCOLOR_FAILURE 等的颜色配置

/etc/sysconfig/init

例子:

# color => new RH6.0 bootup
# verbose => old-style bootup
# anything else => new style bootup without ANSI colors or positioning
BOOTUP=color
# column to start "[  OK  ]" label in 
RES_COL=60
# terminal sequence to move to that column. You could change this
# to something like "tput hpa ${RES_COL}" if your terminal supports it
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
# terminal sequence to set color to a 'success' color (currently: green)
SETCOLOR_SUCCESS="echo -en \\033[0;32m"
# terminal sequence to set color to a 'failure' color (currently: red)
SETCOLOR_FAILURE="echo -en \\033[0;31m"
# terminal sequence to set color to a 'warning' color (currently: yellow)
SETCOLOR_WARNING="echo -en \\033[0;33m"
# terminal sequence to reset to the default color.
SETCOLOR_NORMAL="echo -en \\033[0;39m"

也许您可以使用这些信息和名称来查找系统上的正确文件:)

答案2

这些定义位于/etc/init.d/functions.

该脚本尝试获取/etc/sysconfig/init,其中包含相关的颜色定义:

SETCOLOR_SUCCESS="echo -en \\033[0;32m"
SETCOLOR_FAILURE="echo -en \\033[0;31m"
SETCOLOR_WARNING="echo -en \\033[0;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"

...而原始/etc/init.d/functions文件定义了各种状态消息的函数,例如:

echo_success() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
  echo -n $"  OK  "
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo -n "]"
  echo -ne "\r"
  return 0
}

...因此,如果您想发出某些内容而不是OK,您可以编辑该echo语句,如果您想更改颜色,您可以编辑/etc/sysconfig/init;中的相应定义。如果您没有该文件,请注意functions脚本将定义颜色本身(在else测试文件是否存在的子句中init)。

相关内容