You are not logged in.
Hello,
I would like to receive a regular email containing results of the following commands:
locate *file*
nano *file*
Is this possible?
Thanks.
Offline
nano file wouldn't give you any results...do you mean cat?
Offline
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
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)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
locate is working but cat doesn't send an email.
Offline
No need to cat a file when sending via "mail" command. Just redirect io :
mail -s "Some Subject" someuser@domain < file2send
Offline
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
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
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
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
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
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:
[...] 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
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
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.
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
man logrotate
very simple and already implemented in arch.
Offline
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
What are you actually trying to achieve? Does Logwatch suit your needs?
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
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
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)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
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
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)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
[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
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...
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
[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
Do you have the mailx package installed? Can you post the contents of /etc/logrotate.d/access_logsh please?
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline