mail output on prompt

2019-08-20 13:00发布

问题:

I have developed a script in linux bash that is running in background and send emails when something related is found. Here is mail code of that script.

mail -s "Backup File place XYZ.... " "$EMAIL" 

There is no body of that email as everything is covered in subject. but problem is that whenever it sends an email i get ouptput on console saying

" Null message body; hope that's ok".... 

Now I want dont want this text. how can i stop it.

回答1:

From Bash Version 4 onwards

mail -s "$text" "$email" &> /dev/null

should redirect stdout and stderr to /dev/null



回答2:

You could always just route the output to the bit bucket:

 mail -s "Backup File place XYZ.... " "$EMAIL" > /dev/null 2> /dev/null

This, of course, assumes you don't care if you actually see errors there.



标签: linux bash email