我有下面的代码,它不会发送grep输出到电子邮件,但它显示输出命令行。不知道我做错了运行bash命令后没有收到grep输出的邮件
sudo tail -f /path/to/file | while read line ; do
egrep 'successfully started \[[0-9] out of [0-9]\] components|successfully started \[[0-9] out of [0-9]\] components'
if [ $? -eq 0 ]; then
(echo " RESTARTS"; echo; echo $line) | mail -s "RESTART" [email protected]
else
echo " FAILS"
fi
done
[更新]
还有一种办法,我想这样做,但它不会发送email..I只是确保我能摆脱循环,不会永远持续下去,因此这就是为什么我把尾巴而
while read line; do
echo "$line" | sudo tail -f /opt/bmc/ao/cdp/tomcat/logs/grid.log
if [ $(echo "$line" | grep -E 'successfully started \[[0-9] out of [0-9]\] components|successfully started \[[0-9] out of [0-9]\] components' | wc -l) -ne 0 ]; then
(echo "CDP RESTARTS"; echo; echo "$line") | mail -s "BAOCDP AUTO RESTART" [email protected]
break
fi
done
取出(脚本 –
OK,我会尝试的 –
@RamanSailopal这将无法正常工作,只有'echo $ line'会被传送到'mail',而前两个回声会进入stdout – Aaron