Originally Posted by Sigg3.net
In my experience, the CAT << redirection does not work in bash scripts (as it does in "interactive" mode).
Huh? That's not a "trick", it's just a standard here document
, and will work with any command that can accept text from stdin.
The only problem I see here is that the OP is trying to send the input into grep
, which is already reading data from a file and so will ignore it. This just means that the output has to be reconfigured to be sent into mail correctly.
This could be done with a command substitution inside the heredoc, among other techniques. No need for any external files.
cat << EOF | /usr/sbin/sendmail -t
$( grep - $(date +"%Y-%m-%d" --date="1 days ago") /var/log/fail2ban.log )
And in fact, I don't see the need for a heredoc either. A simple command grouping can do the trick just as well.
grep - $(date +"%Y-%m-%d" --date="1 days ago") /var/log/fail2ban.log
} | /usr/sbin/sendmail -t
PS: See my reply in the OP's previous thread about grep
ping the logfile.