我需要一个bash脚本,它接受shell命令的输出并解析输出以提取状态。如果国家是:坏的,应该发送电子邮件。
~$ bucardo status
PID of Bucardo MCP: 2074
Name State Last good Time Last I/D Last bad Time
============================================+========+=======================+==============+===========+=======================+==============
zenith | Good | Jun 28, 2020 08:37:45 | 31h 13m 14s | 1/1 | Jun 22, 2020 12:28:34 | 171h 22m 25s
zenith | Good | Jun 23, 2020 19:12:42 | 140h 38m 17s | 4/4 | none | 我还没能把Regex弄对
#!/usr/bin/env bash
bucardo status
while read line; do
if [[ ! ${line} =~ ^[\+\| ]]; then
if [[ ${line} =~ \|[[:space:]]*([[:alpha:]]+)[[:space:]]*\ ]]; then
state="${BASH_REMATCH[1]}"
echo "${state}"
fi
fi
done发布于 2021-03-03 09:44:57
if [[ ${line} =~ \|[[:space:]]*([[:alpha:]]+)[[:space:]]*\ ]]; then应该是
if [[ ${line} =~ \|[[:space:]]*([[:alpha:]]+)[[:space:]]* ]]; then(移除多余的\)。现在对我有用了。
提示:如果您使用Vim,语法高亮显示会使您立即跳出来!
https://serverfault.com/questions/1023369
复制相似问题