View previous topic :: View next topic |
Author |
Message |
gopher2 n00b
Joined: 10 Oct 2005 Posts: 38
|
Posted: Sat Mar 28, 2009 3:26 pm Post subject: send file via email ? |
|
|
I have a program running like this
program --log file.log
i monitor the log file for events via
tail -f file.log | grep event
how can i have my self emailed of these particular events
something like?
tail -f file.log | grep event > sendmail me@email.com ?
thanks guys |
|
Back to top |
|
|
ecroy n00b
Joined: 08 Nov 2002 Posts: 59
|
Posted: Sat Mar 28, 2009 4:36 pm Post subject: |
|
|
I don't think there is a solution as simple as that. You _might_ probably achieve it by doing some hackish trickery like:
Code: | while :; do tail -n1 -f file.log | grep -m1 "event" | sed "s/event/mailheader\nevent-description/" | sendmail your@email; done |
but apart from being error-prone it is also very ugly. The proper solution would be to get your program log to your system-logger of choice and use its e-mail alert capability. |
|
Back to top |
|
|
think4urs11 Bodhisattva
Joined: 25 Jun 2003 Posts: 6659 Location: above the cloud
|
Posted: Sat Mar 28, 2009 4:54 pm Post subject: |
|
|
you may want to take a look at net-analyzer/sec _________________ Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself |
|
Back to top |
|
|
doctork Guru
Joined: 25 Apr 2004 Posts: 370 Location: Cleveland, OH
|
Posted: Sat Mar 28, 2009 5:56 pm Post subject: |
|
|
I've used things like this in the past:
Code: | tail -f file.log | grep event | mailx -s "An event message" target@somewhere.com |
This assumes that there's some MTA on the system capable of sending mail (sendmail).
EDIT: I can't say I've used it with a tail -f. That will require a bit of work to terminate the file being sent by mailx. I'll leave that as an exercise for the reader
--
doc |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3943 Location: Hamburg
|
Posted: Sat Mar 28, 2009 6:20 pm Post subject: |
|
|
doctork wrote: | I've used things like this in the past:
Code: | tail -f file.log | grep event | mailx -s "An event message" target@somewhere.com |
This assumes that there's some MTA on the system capable of sending mail (sendmail).
EDIT: I can't say I've used it with a tail -f. That will require a bit of work to terminate the file being sent by mailx. I'll leave that as an exercise for the reader
--
doc | I'd bet that no mail is send as long as the tail command is running. |
|
Back to top |
|
|
|