[SOLVED] Fail2ban email - custom

both

cat /var/log/asterisk/full.NimbusDemo|grep -i reach

and

cat /var/log/asterisk/full.NimbusDemo|while read i;do if [[ $i =~ REACH || $i =~ Reach ]];then echo $i ;fi;done

found the unreachable notices we wanted. also the “Does this work”|mail myemail address did send me an email

but,

tail -F /var/log/asterisk/full.NimbusDemo|while read i;do if [[ $i =~ “UNREACHABLE!” ]];then echo $i|mail [email protected] ;fi;done

is not sending me an email when the device goes unreachable? any ideas?

Not really, check your mail log.

i altered the command in the rc.local file. You mentioned I needed to run the command?

You should only add anything to rc.local when it is working, debug it first. You will have to kill that script or confuse yourself.

That’s IT!!! I restarted and tested and got the message!! You the man. Thank you very much for your help!

Then mark your thread solved.

I’m attempting to revive this on a second system and have two questions:

  1. you mentioned I need to run /etc/rc.local or reboot. Reboot is not an option right now, how to I go about running /etc/rc.local?

  2. I ran cat /var/log/httpd/access_log|while read i;do if [[ $i =~ module=dashboard ]];then echo $i|mail my actual email address ;fi;done

and it works but I want it to stop! Is there any way to stop this cat command?

/etc/rc.local is executable just type it at the bash prompt

ps aux|grep dashboard will reveal the pid of the process

kill (that pid)

1 Like

When I run this command it just hangs forever until I cancel it out.

Post the issue of

bash -x /etc/rc.local

My guess is you forgot the terminal & that puts it to the background.

I’m starting to see what might be going on. running your command produces a massive number of entries which probably explains why it’s hanging. I was searching the httpd access file which was massive. It was reading through each line and looking for a match. I truncated the httpd access file and ran the command again to see if it hangs.

This is the search command I placed in the file with your previous help. I tested it with cat first and it worked

tail -F /var/log/httpd/access_log|while read i;do if [[ $i =~ module=dashboard ]];then echo $i|mail [email protected] ;fi;done

Putting the process to the background allows the script to continue, no matter what, the whole idea is that process is always running and will never return.