你能帮助我,请发送电子邮件,如果超过100例如更大的列$ 3·
host@root:> report_alias | awk '{ if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" [email protected] ;}}'
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" [email protected] ;}}
awk: ^ syntax error
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" [email protected] ;}}
awk: ^ syntax error
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" [email protected] ;}}
awk:
“报告别名”的输出
Flow REPORT 1 3,450 has problems
Flow REPORT 2 3,154 has problems
Flow REPORT 3 134 has problems
Flow REPORT 4 134 has problems
Flow REPORT 5 has problems
Flow REPORT 6 has problems
尝试这个。
report_alias |
awk '$3 >= 100 { print "FLOW" $1, $2, $3 " has problems"}' |
mailx -s "FILES REPORT" [email protected]
如果没有在AWK中输出这将发送空消息。一个常见的解决方法是将输出保存到临时文件,检查它是否为空,然后只如果没有,发送消息。
#!/bin/sh
t=$(mktemp -t report_alias.XXXXXXXXX) || exit
trap 'rm -f $t' EXIT
trap 'exit 1' HUP INT TERM
report_alias |
awk '$3 >= 100 { print "FLOW" $1, $2, $3 " has problems"}' >"$t"
if [ -s "$t" ]; then
mailx -s "FILES REPORT" [email protected] <"$t"
fi