mail output on prompt

2019-08-20 12:56发布

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.

标签: linux bash email
2条回答
贼婆χ
2楼-- · 2019-08-20 13:33

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.

查看更多
太酷不给撩
3楼-- · 2019-08-20 13:50

From Bash Version 4 onwards

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

should redirect stdout and stderr to /dev/null

查看更多
登录 后发表回答