LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-23-2009, 04:25 PM   #1
emgee3
LQ Newbie
 
Registered: May 2009
Posts: 14

Rep: Reputation: 1
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
 
Old 11-23-2009, 07:04 PM   #2
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Quote:
Originally Posted by emgee3 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian etch - Unable to send mail from command line or from php mail command lqforumuser Linux - Newbie 1 03-01-2009 06:56 AM
command line email client to send mail to remote mail server dhanju Linux - Software 1 03-07-2008 06:37 AM
How to log off a user from command line raazman Linux - General 3 05-11-2007 07:43 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
log into the command line only screen at bootup chongluo Linux - Newbie 2 03-26-2004 02:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration