You are not logged in.

#1 2008-07-18 22:16:50

RAH
Member
Registered: 2008-06-20
Posts: 205

Server Email

Hello,

I would like to receive a regular email containing results of the following commands:

locate *file*
nano *file*

Is this possible?

Thanks.

Offline

#2 2008-07-18 22:37:52

Abelian
Member
Registered: 2008-04-23
Posts: 63

Re: Server Email

nano file wouldn't give you any results...do you mean cat?

Offline

#3 2008-07-18 22:48:34

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: Server Email

you could make a cronjob to output the results to a file. Don't know about emailling it tho


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#4 2008-07-19 00:36:37

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

You can use cron... To edit your cron file:

export EDITOR=/usr/bin/nano
crontab -e

Then add these 2 lines to get daily e-mail at 2.00am

0 2 * * *   /usr/bin/locate *file* | mail -s "locate output" your@emailaddress.com
0 2 * * *   /bin/cat *file* | mail -s "cat output" your@emailaddress.com

EDIT: brain fart.

Last edited by fukawi2 (2008-07-19 00:36:58)

Offline

#5 2008-07-19 00:40:27

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

locate is working but cat doesn't send an email.

Offline

#6 2008-07-19 13:04:32

dschrute
Member
From: NJ, USA
Registered: 2007-04-09
Posts: 183

Re: Server Email

No need to cat a file when sending via "mail" command.  Just redirect io :

mail -s "Some Subject" someuser@domain < file2send

Offline

#7 2008-07-19 13:24:34

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

dschrute wrote:

No need to cat a file when sending via "mail" command.  Just redirect io :

mail -s "Some Subject" someuser@domain < file2send

This doesn't send an email either.

Offline

#8 2008-07-19 13:40:32

dschrute
Member
From: NJ, USA
Registered: 2007-04-09
Posts: 183

Re: Server Email

This doesn't send an email either.

Are there any error messages ?  What happens when you run it directly ?
Sounds like either a permissions issue, or the address you're sending to or path to the file is wrong.

Offline

#9 2008-07-19 13:47:28

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

dschrute wrote:

This doesn't send an email either.

Are there any error messages ?  What happens when you run it directly ?
Sounds like either a permissions issue, or the address you're sending to or path to the file is wrong.

No error is given.  The file path is correct.  I think I've discovered the problem - the file is over 100mb.  How would I overcome this?  It's a very big log file.

Offline

#10 2008-07-19 14:16:41

dschrute
Member
From: NJ, USA
Registered: 2007-04-09
Posts: 183

Re: Server Email

No error is given.  The file path is correct.  I think I've discovered the problem - the file is over 100mb.  How would I overcome this?  It's a very big log file.

gzip and send as attachment ?  Or use rotate the logs more frequently + send the smaller file(s).

Offline

#11 2008-07-19 14:18:55

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

dschrute wrote:

No error is given.  The file path is correct.  I think I've discovered the problem - the file is over 100mb.  How would I overcome this?  It's a very big log file.

gzip and send as attachment ?  Or use rotate the logs more frequently + send the smaller file(s).

Those are good ideas however would it be possible to send text from the file which matches a certain criteria - eg. the current date.  I'm not sure how to rotate the logs.  It's part of LayeredPanel system and I'm not sure how it rotates them.

Offline

#12 2008-07-19 14:23:30

smoon
Member
Registered: 2005-08-22
Posts: 468
Website

Re: Server Email

fukawi2 wrote:

You can use cron... To edit your cron file:

export EDITOR=/usr/bin/nano
crontab -e

Then add these 2 lines to get daily e-mail at 2.00am

0 2 * * *   /usr/bin/locate *file* | mail -s "locate output" your@emailaddress.com
0 2 * * *   /bin/cat *file* | mail -s "cat output" your@emailaddress.com

EDIT: brain fart.

There's no need to run the mail command manually - at least if you want to send the mail to the user who owns the crontab:

man crontab wrote:

[...] It is also common to redirect output to a log file.  If you  do not,  and  the command generates output on stdout or stderr, the result will be mailed to the user in question. [...]

Offline

#13 2008-07-22 00:36:29

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

RAH wrote:

Those are good ideas however would it be possible to send text from the file which matches a certain criteria - eg. the current date.  I'm not sure how to rotate the logs.  It's part of LayeredPanel system and I'm not sure how it rotates them.

Anyone know how to do this?

Offline

#14 2008-07-22 01:13:03

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

I'm not quite sure I understand you, but you want to e-mail the contents of a log file with a certain date stamp?

If that's correct, then you can use grep to match the date and e-mail that to you... For example, if you have this log file:

Jul 22 00:16:50 lapp ntpd[2316]: adjusting local clock by 0.156253s
Jul 22 00:23:04 lapp named[2111]: unexpected RCODE (SERVFAIL) resolving 'orgo.progsoc.uts.edu.au/A/IN': 138.25.8.1#53
Jul 22 01:14:44 lapp ntpd[2316]: adjusting local clock by 0.161520s
Jul 22 01:41:33 lapp ntpd[2316]: adjusting local clock by 0.128306s
Jul 22 02:30:02 lapp ntpd[2316]: adjusting local clock by 0.240360s
Jul 22 03:23:35 lapp named[2111]: unexpected RCODE (SERVFAIL) resolving 'orgo.progsoc.uts.edu.au/A/IN': 138.25.8.1#53
Jul 22 03:32:07 lapp ntpd[2316]: adjusting local clock by 0.172249s
Jul 22 03:39:14 lapp ntpd[2316]: adjusting local clock by 0.219427s
Jul 22 04:48:14 lapp ntpd[2316]: adjusting local clock by 0.241630s
Jul 22 05:42:58 lapp ntpd[2316]: adjusting local clock by 0.156146s
Jul 22 05:52:03 lapp ntpd[2316]: adjusting local clock by 0.163046s
Jul 22 06:53:25 lapp ntpd[2316]: adjusting local clock by 0.243436s
Jul 22 06:59:46 lapp ntpd[2316]: adjusting local clock by 0.302340s
Jul 22 07:39:33 lapp ntpd[2316]: adjusting local clock by 0.166153s
Jul 22 08:35:50 lapp ntpd[2316]: adjusting local clock by 0.300648s
Jul 22 08:43:52 lapp ntpd[2316]: adjusting local clock by 0.219453s
Jul 22 08:50:37 lapp ntpd[2316]: adjusting local clock by 0.194876s
Jul 22 09:35:24 lapp ntpd[2316]: adjusting local clock by 0.315070s
Jul 22 09:44:38 lapp ntpd[2316]: adjusting local clock by 0.173083s
Jul 22 10:20:17 lapp ntpd[2316]: adjusting local clock by 0.146004s

Then you could match the "Jul 22" part and e-mail that:

egrep '^Jul 22' /path/to/log/file | mail -s "July 22 Logs" your@emailaddress.com

To be able to dynamically take "yesterdays" (as opposed to a specific date) logs is going to be a bit more difficult.

I'm not sure exactly what your end goal is, but if you want to review your logs on a daily basic, have you seen Logwatch?
http://www.logwatch.org/

Logwatch is a customizable log analysis system. Logwatch parses through your system's logs for a given period of time and creates a report analyzing areas that you specify, in as much detail as you require. Logwatch is easy to use and will work right out of the package on most systems.

Offline

#15 2008-07-22 01:18:47

rooloo
Member
Registered: 2008-07-09
Posts: 218

Re: Server Email

man logrotate

very simple and already implemented in arch.

Offline

#16 2008-07-22 21:25:05

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

I have read the logrotate man page and looked at the config file however I'm still not entirely sure how to use it.

Offline

#17 2008-07-23 00:26:19

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

What are you actually trying to achieve? Does Logwatch suit your needs?

Offline

#18 2008-07-23 02:01:14

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

fukawi2 wrote:

What are you actually trying to achieve? Does Logwatch suit your needs?

Rotate a particular log on a daily basis and email it to me.

Offline

#19 2008-07-23 04:50:45

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

Add this to /etc/logrotate.d/YOUR_LOG_NAME

/path/to/log.file {
        missingok
        daily
        prerotate
                /usr/bin/mail -s "Log for `date +%x`" your@emailaddress.com < /path/to/log.file || true
        endscript
}

Obviously change the /path/to/log.file and your@emailaddress.com to the appropriate strings (don't forget the 2nd instance of /path/to/log.file)

That will make logrotate roll that log daily, renaming the old file to log.file.1, and the one before that to log.file.2 and so on, but before it rolls it, it will execute the mail line. I'll leave it as an exercise for the reader to work out exactly what it does (it does e-mail you the log)

Last edited by fukawi2 (2008-07-23 04:52:48)

Offline

#20 2008-07-23 12:58:59

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

I've set this up - thank you.

However I've tried running the following and nothing appears to happen.
logrotate /etc/logrotate.d/access_log

Offline

#21 2008-07-23 13:19:18

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

Try:

logrotate -d /etc/logrotate.d/access_log

Have a look through that to see if you can find the problem... Post the output and the contents of access_log here for us if you can't...

Last edited by fukawi2 (2008-07-23 13:19:46)

Offline

#22 2008-07-23 15:29:10

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

[root@server ~]# logrotate -d /etc/logrotate.d/access_log
reading config file /etc/logrotate.d/access_log
reading config info for /home/freeunlimitedweb.com/runtime_layeredpanel/var/log/httpd/access_log.users 


Handling 1 logs

rotating pattern: /home/freeunlimitedweb.com/runtime_layeredpanel/var/log/httpd/access_log.users 
 after 1 days (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /home/freeunlimitedweb.com/runtime_layeredpanel/var/log/httpd/access_log.users
  log does not need rotating
not running prerotate script, since no logs will be rotated

Offline

#23 2008-07-24 06:36:16

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

Looks like it is going to wait 1 day before it's first log roll... You can use -f to force it to do it now if you don't want to wait...

Offline

#24 2008-07-24 11:27:40

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Server Email

[root@server ~]# logrotate -f /etc/logrotate.d/access_logsh: line 1: /usr/bin/mail: No such file or directory
sh: -c: line 3: syntax error near unexpected token `newline'
sh: -c: line 3: `email@email.com < '
error: error running shared prerotate script for /home/freeunlimitedweb.com/runtime_layeredpanel/var/log/httpd/access_log.users

Offline

#25 2008-07-24 11:59:22

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Server Email

Do you have the mailx package installed? Can you post the contents of /etc/logrotate.d/access_logsh please?

Offline

Board footer

Powered by FluxBB