WebFaction
Community site: login faq

Can someone suggest a way to email server logs.

i.e, whenever something is written into error_yourapp.log file mail it to me

not a time out fashion but i should get an email the next second there is an entry into the error_app.log file ..

asked 26 Jun '13, 05:24

boltsfromthe...
1314
accept rate: 0%


Many applications and frameworks have this capability built into them. Check the documentation for whatever application you are using to see if it does.

For example, if you're using Django: Email reports

If the application you're using does not have this capability, then there are some solutions here that might work for you: How to execute a command whenever a file changes?

Hope that helps!

permanent link

answered 26 Jun '13, 13:17

seanf
12.2k41836
accept rate: 37%

I came here looking for a more generic answer. I ended up writing this:

#!/bin/bash

errorcount=`find /home/bovisync/logs/user/ -regex '.*/error.*[^1-9]$' -size +10c -mmin -30 -ls | wc -l`
if [ $errorcount -gt 0 ]; then
    mailmsg="There was a server error on webfaction. Check the logs at ~/logs/user/"
    echo "$mailmsg" | mail -s WebfactionError you@example.com
    echo "$mailmsg"
fi
exit 0

This will count the logs with a name which begin with "error", that have been modified in the past 30 minutes, and send you an email if it finds any. Set this up as a cron job to run every 15 minutes or so.

Edit: my original script forgot about log rotation. So the edited version ignores files that end in a number, and only reports files which are over 10 bytes in size.

permanent link

answered 01 Aug '14, 11:14

ndudenhoeffer
1127
accept rate: 0%

edited 02 Aug '14, 10:55

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×261
×108
×28

question asked: 26 Jun '13, 05:24

question was seen: 2,495 times

last updated: 02 Aug '14, 10:55

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM