Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 发送带有awk输出列的电子邮件_Linux_Awk - Fatal编程技术网

Linux 发送带有awk输出列的电子邮件

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

如果列$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 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