I have a lynis script that I use to scan my server. This script is not important to demonstrate but here is the script anyway: https://gitlab.com/sofibox/maxicron/-/blob/master/usr/local/maxicron/lynis/maxinis

This script runs perfectly and doesn't output any errors when running it manually like this through terminal:

./maxinis manual --cronjob

I also will receive an email about the scan

But, when I run this script via cronjob at specific time like this:

06 21 * * *     root    /usr/local/maxicron/lynis/maxinis cron --cronjob > /dev/null

It also run perfectly, send an email but I got an extra email from Cron Daemon with 3 warning outputs like this:

Cron Daemon Email


My question is, based on the 3 warning messages from the picture above, I got cron daemon email warning. How do I suppress the second line of the warning and keep the rest output sent by Cron Daemon ?

The second line of the output is:

# Warning: iptables-legacy tables present, use iptables-legacy to see them

I tried using this grep -v method like this in the crontab but doesn't seems to work:

06 21 * * *     root    /usr/local/maxicron/lynis/maxinis cron --cronjob > /dev/null | grep -v '# Warning: iptables-legacy tables present, use iptables-legacy to see them' 

1 Answer 1


The reason grep isn't working is that the messages are going to stderr, not stdout, so grep is never seeing them. That's why you're getting an email even after sending stdout to /dev/null. You can filter stderr like this:

somecommand > /dev/null 2>( grep -v 'unwanted error' 1>&2 )
  • Thanks a lot for mentioning about stderr and stdout. The command you given is not working. This one is working: somecommand 2>&1 > /dev/null | grep -Ev "# Warning: iptables-legacy tables present, use iptables-legacy to see them|another-output"
    – MaXi32
    Jul 30, 2020 at 16:24
  • 1
    the 2>( ) syntax may need a newer version of bash than you have installed. If you're okay with stderr being shunted into stdout, your alternative method works nicely.
    – DopeGhoti
    Jul 30, 2020 at 16:48
  • thank you so much for the best explanation here.
    – MaXi32
    Jul 30, 2020 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .