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@address.com 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@address.com 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@address.com > /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@address.com &)