LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Watch log file from command line and e-mail (https://www.linuxquestions.org/questions/linux-general-1/watch-log-file-from-command-line-and-e-mail-771075/)

emgee3 11-23-2009 04:25 PM

Watch log file from command line and e-mail
 
I'd like a script that will e-mail me when it detects a certain line in a log file. I know I could do this by installing a log watching program and set it to run every 5 minutes. However, I don't want to install software on the server, I'd prefer a simple script to do this.

Something like:

Code:

tail -f /var/log/apache2/access_log | grep "GET /file.html HTTP/1.1" | mail -s "alert" my@email.com
but obviously something that works, as opposed to the above :)

frenchn00b 11-23-2009 07:04 PM

Quote:

Originally Posted by emgee3 (Post 3767274)
I'd like a script that will e-mail me when it detects a certain line in a log file. I know I could do this by installing a log watching program and set it to run every 5 minutes. However, I don't want to install software on the server, I'd prefer a simple script to do this.

Something like:

Code:

tail -f /var/log/apache2/access_log | grep "GET /file.html HTTP/1.1" | mail -s "alert" my@email.com
but obviously something that works, as opposed to the above :)

cat .muttrc

set sendmail="/usr/bin/msmtp"
unset use_from

#set query_command="abook --mutt-query '%s'"
#macro pager A |'abook --add-email'\n

set query_command = "abook --mutt-query '%s'"
macro generic,index,pager \ca "<shell-escape>abook<return>" "launch abook"
macro index,pager A "<pipe-message>abook --add-email<return>" "add the
sender address to abook"

unset reply_self # if unset, a reply to yourself implies reply to
other
my_hdr Reply-To: me@gmail.com


cat .msmtprc


account default
host smtp.gmail.com
port 587
from me@gmail.com
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
user me@gmail.com
password secretsecret
logfile ~/.msmtp.log


installation:

> apt-get -f -y --allow-unauthenticated install
> apt-get -f -y --allow-unauthenticated install mutt
> apt-get -f -y --allow-unauthenticated install libssl
> apt-get -f -y --allow-unauthenticated install openssl libssl0.9.7
> apt-get -f -y --allow-unauthenticated install sendmail-bin
>
> apt-get -f -y --allow-unauthenticated install msmtp
>



and crontab -e
15 7 * * * cd ; echo "hello" | mutt me@gmail.com


All times are GMT -5. The time now is 04:28 AM.