LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Email Logs Slackware 12 (http://www.linuxquestions.org/questions/slackware-14/email-logs-slackware-12-a-589247/)

thoron! 10-03-2007 07:54 PM

Email Logs Slackware 12
 
I want to be able to email myself from a cron job.

I have this set up using ssmtp on my router but I would like my web server box to do something similar.

Tutorials that I have went though don't seem to get me anywhere.

ssmtp was nice since I could use a gmail account to send messages from.

Alien_Hominid 10-04-2007 12:11 AM

Can you elaborate more about your problem?

thoron! 10-04-2007 01:00 AM

i think i basically need a script that will email me httpd logs or logs from /var/log that i can cron to send them at a certain time each day

rworkman 10-04-2007 10:54 AM

Look into using mailx(1)

pricejm 10-06-2007 10:34 AM

Hi,

I'm the guy thoron posted this for...

I've gotton this far:

Using mailx to use smtp.gmail.com, since I can't send mail directly to the gmail account (invalid ip address, would have to relay through isp smtp...).

mailx -v -s Test -S smtp-use-starttls -S smtp-auth=login -S smtp=smtp.gmail.com:587 -S from=fromEmail@gmail.com -S smtp-auth-user=user@gmail.com -S smtp-auth-password="password" toEmail@gmail.com

This results in:

Code:

Resolving host smtp.gmail.com . . . done.
Connecting to 64.233.185.111 . . . connected.
220 mx.google.com ESMTP g9sm5349298wra
>>> EHLO serverName.com
250-mx.google.com at your service, [68.58.162.123]
250-SIZE 28311552
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
>>> STARTTLS
220 2.0.0 Ready to start TLS
Error with certificate at depth: 0
 issuer = /C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Premium Server CA/emailAddress=premium-server@thawte.com
 subject = /C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
 err 20: unable to get local issuer certificate
Continue (y/n)? could not initiate SSL/TLS connection: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
"/home/pricejm/dead.letter" 11/315
. . . message not sent.


pricejm 10-06-2007 10:44 AM

Ok I added "-S ssl-verify=ignore" and it went through.

Maybe I need to grab a cert and save it?

Now figuring that one out...

pricejm 10-06-2007 12:33 PM

This is what I concluded with:

Code:

#! /bin/sh

ACCESS_LOG=/var/log/httpd/access_log
ERROR_LOG=/var/log/httpd/error_log
SMTP=smtp.gmail.com:587
FROM_MAIL=fromMail@gmail.com
LOGIN=logIn@gmail.com
LOGIN_PASSWORD=password
TO_MAIL=toMail@gmail.com

#Email access log
SUBJECT='httpd Access Log'
cat $ACCESS_LOG | mailx $1 -s "$SUBJECT" -S ssl-verify=ignore -S smtp-use-starttls -S smtp-auth=login -S smtp="$SMTP" -S from="$FROM_MAIL" -S smtp-auth-user="$LOGIN" -S smtp-auth-password="$LOGIN_PASSWORD" $TO_MAIL

#Email error log
SUBJECT='httpd Error Log'
cat $ERROR_LOG | mailx $1 -s "$SUBJECT" -S ssl-verify=ignore -S smtp-use-starttls -S smtp-auth=login -S smtp="$SMTP" -S from="$FROM_MAIL" -S smtp-auth-user="$LOGIN" -S smtp-auth-password="$LOGIN_PASSWORD" $TO_MAIL

#Truncate logs
echo -n > $ACCESS_LOG
echo -n > $ERROR_LOG

Now I can just throw this script at cron and just check my email. I have another GMail account that is used to sends the messages, don't have to bother with the Sent mail and this clear text pword. I just put a filter that applies a label to the particular email in GMail. Makes storing logs pretty easy.

I'd rather not have to ignore the ssl failures but I'll save that for another day.

Thank you thoron for starting this and rworkman for pointing me to mailx.


All times are GMT -5. The time now is 08:47 AM.