【发布时间】:2018-07-02 19:20:02
【问题描述】:
我每周运行一个 crontab 来收集信息并创建一个日志文件。
我有一个脚本,我针对这个每周文件运行以仅将特定状态行输出到我的显示器。
#!/bin/sh
# store newest filename to variable
HW_FILE="$(ls -t /home/user/hwinfo/|head -1)"
# List the Site name, hardware group, Redundancy or Health status', and the site divider
grep -i 'Site\|^\*\*\|^Redundancy\|^Health\|^##' /home/user/hwinfo/$HW_FILE
echo "/home/user/hwinfo/"$HW_FILE
exit 0
这是一个示例输出:
Accessing Site: site01
** FANS **
Redundancy Status : Full
** MEMORY **
Health : Ok
** CPUs **
Health : Ok
** POWER SUPPLIES **
Redundancy Status : Full
##########################################
Accessing Site: site02
** FANS **
Redundancy Status : Full
** MEMORY **
Health : Degraded
** CPUs **
Health : Ok
** POWER SUPPLIES **
Redundancy Status : Full
##########################################
Accessing Site: site03
** FANS **
Redundancy Status : Failed
** MEMORY **
Health : Ok
** CPUs **
Health : Ok
** POWER SUPPLIES **
Redundancy Status : Full
##########################################
/home/user/hwinfo/hwinfo_102217_034001.txt
有没有办法 cat / grep / sed / awk / perl / 当前输出,以便任何以Redundancy 或Health 开头但不以Full 或Ok 结尾的行,分别被着色?
我想看到的是这个
我尝试将当前输出通过管道传输到| grep --color=auto \bRedundancy\w*\b(?<!Full)\|\bHealth\w*\b(?<!Ok),但没有成功。任何帮助将不胜感激。
【问题讨论】: