ads2 cls create | awk -F [\"] '/^>>> cluster established .../ { strt=1 } strt!=1 { next } $1 ~ "name" { cnt++;nam[cnt]=$2 } $1 ~ "state" {stat[cnt]=$2;print -e "Node "nam[cnt]" has state "$2 } END { if (stat[1]=="3" && stat[2]=="3") { print "Cluster established. Starting session manager" } else { print "Failed" } }
上面的命令给出了ads2 cls create
检查awk
某些输出变量的输出,并基于它返回"Cluster established. Starting session manager"
或Failed
但是,我正在尝试green
为第一个和第二个“红色”着色这些输出。我在互联网上搜索并没有找到任何与使用print
命令打印的彩色文本相关的内容,而是使用echo -e
命令。
那么如何为这两个输出着色,但是使用当前的实现!
该命令的输出ads2 cls create
如下所示
kernel with pid 3336 (port 9011) killed
kernel with pid 16406 (port 9011) killed
probing service daemon @ http://xx.xx.x.xx:9010
starting kernel FDT-NB-0144 @ http://xx.xx.0.xx:9011 name=xx-NB-0144 max_consec_timeouts=10 clustermode=Standard hostname=FDT-NB-0144 framerate=20000 schedmode=Standard rtaddr=xx.xx.x.xx tickrole=Local tickmaster=local max_total_timeouts=1000
kernel FDT-NB-0144 running
probing service daemon @ http://xx.xx.xx.xx:9010
starting kernel fdt-c-agx-0008 @ http://xx.xx.xx.18:9011 name=fdt-c-agx-0008 max_consec_timeouts=10 clustermode=Standard hostname=nvidia@fdt-c-agx-0008 framerate=20000 schedmode=Standard rtaddr=xx.xx.xx.xx tickrole=Local tickmaster=local max_total_timeouts=1000
kernel fdt-c-agx-0008 running
>>> start cluster establish ...
>>> cluster established ...
nodes {
node {
name = "xxx-c-agx-0008";
address = "http://xx.xx.xx.xx:9011/";
state = "3";
}
node {
name = "xxx-NB-0144";
address = "http://xx.xx.0.xx:9011/";
state = "3";
}
}
您可以在 awk printf 命令中使用 ANSI 颜色序列,如下所示:
前任:
要在您的情况下应用它,请将
END
块修改为: