当前位置: 动力学知识库 > 问答 > 编程问答 >

bash - hiding stdout with piped mail command

问题描述:

I am trying to hide stdout & stderr from displaying and can't get the syntax right.

I have a one liner in root's .profile to email me whenever there is a root login:

netstat -antp | grep ESTABLISHED | grep -v 127.0.0.1 | mail -s "alert: root access on server" [email protected] 2>&1>/dev/null &

The problem is that after the mail is sent, I get this on stdout:

[1]+ Done mail -s "alert: root access on server" [email protected] 2>&1 > /dev/null

I don't want it to show anything when on the command line when the mail is sent, what am I missing? I also tried this, but no luck:

mail -s "alert: root access on server" [email protected] > /dev/null 2>&1 &

I have to have the "&" at the end or it pauses ~30 seconds before login.

Any ideas on how to send the email, hide the stdout and stderr, and run it as a background program?

Thanks!

网友答案:

(netstat -antp | grep ESTABLISHED | grep -v 127.0.0.1 | mail -s "alert: root access on server" [email protected] &)

分享给朋友:
您可能感兴趣的文章:
随机阅读: