Help with Bash script - email new error messages from several log
by Linux Rookie from LinuxQuestions.org on (#5KSQ8)
Hi,
This is completely new for me (linux and bash noob), but i got the task to write a script to monitor errors or anything that failed from several logs and for every log email separately its newly arrived errors/failures to a central administration emailaddress.
For example for the log of nginx webserver.
I got something like:
#!/bin/bash
SEARCH=GET
SOURCE='/var/log/nginx/access.log'
function GetNewLogs() {
tail -n0 -F $SOURCE | grep --line-buffered $SEARCH
}
GetNewLogs | mail -s "nginx errors hostname" someemail@domain.com
I save this as test.sh and run it in a terminal like ./test.sh
This shell script needs to be scheduled and running all the time even after a reboot.
How can i accomplish this? I had tried to let the function write to a file first and then cat the file to pass to the mail command but it just hangs in the prompt. I am creating the script in a PUTTY window connected to Linux machine.
Thanks for any help.
This is completely new for me (linux and bash noob), but i got the task to write a script to monitor errors or anything that failed from several logs and for every log email separately its newly arrived errors/failures to a central administration emailaddress.
For example for the log of nginx webserver.
I got something like:
#!/bin/bash
SEARCH=GET
SOURCE='/var/log/nginx/access.log'
function GetNewLogs() {
tail -n0 -F $SOURCE | grep --line-buffered $SEARCH
}
GetNewLogs | mail -s "nginx errors hostname" someemail@domain.com
I save this as test.sh and run it in a terminal like ./test.sh
This shell script needs to be scheduled and running all the time even after a reboot.
How can i accomplish this? I had tried to let the function write to a file first and then cat the file to pass to the mail command but it just hangs in the prompt. I am creating the script in a PUTTY window connected to Linux machine.
Thanks for any help.