Linux 发送带有awk输出列的电子邮件
如果列$3大于100,您能帮我发送电子邮件吗Linux 发送带有awk输出列的电子邮件,linux,awk,Linux,Awk,如果列$3大于100,您能帮我发送电子邮件吗 host@root:> report_alias | awk '{ if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" example@host.ro ;}}' awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has prob
host@root:> report_alias | awk '{ if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" example@host.ro ;}}'
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" example@host.ro ;}}
awk: ^ syntax error
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" example@host.ro ;}}
awk: ^ syntax error
awk: { if($3 >= 100) { mailx -s "FILES REPORT" < "FLOW" $1,$2,$3 " has problems" example@host.ro ;}}
awk:
试试这个
report_alias |
awk '$3 >= 100 { print "FLOW" $1, $2, $3 " has problems"}' |
mailx -s "FILES REPORT" example@host.ro
如果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" example@host.ro <"$t"
fi
#/垃圾箱/垃圾箱
t=$(mktemp-t报告_别名.XXXXXXXXX)| |退出
陷阱“rm-f$t”出口
陷阱“出口1”HUP整数项
报告别名|
awk'$3>=100{打印“流”$1、$2、$3“有问题”}'>“$t”
如果[-s“$t”];然后
mailx-s“文件报告”example@host.ro您正在尝试执行mailx
,它不是awk的内置程序。尝试awk'$3>=100{system(“echo\”我正在执行一个系统命令,因为\''$3);next}输入
#!/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" example@host.ro <"$t"
fi