LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Adding new cronjob (https://www.linuxquestions.org/questions/linux-general-1/adding-new-cronjob-41788/)

Virtus 01-17-2003 05:25 AM

Adding new cronjob
 
Im still new to the linux world, so i just want to have my cronjob confirmed =)

What i need is to mail
/var/log/messages
/var/log/boot.log
/var/log/cron
/var/log/secure
Every saturday night @ 11 50 - 56Pm

crontab -e
23 50 * * 6 cat /var/log/messages | mail my@email.dk
23 52 * * 6 cat /var/log/boot.log | mail my@email.dk
23 54 * * 6 cat /var/log/cron | mail my@email.dk
23 56 * * 6 cat /var/log/secure | mail my@email.dk

Should be correct right ??
Thanks in advance..

Virtus.

unSpawn 01-17-2003 09:08 AM

6=sat, 7=sun
Btw, if your logs grow large this is gonna be one hell of a mail!
Also you could wrap these actions together with an intermediate script, save it outside one of the cron dirs, I use /etc/cron.scripts:

Code:

#!/bin/sh
# filename
f=cron.$(date +%m%d%Y).tgz
# make a tarball
tar -czf /tmp/${f} /var/log/{messages,boot.log,cron,secure}
# make attachment
makemime -c -N "${f}" -o /tmp/${f}.msg /tmp/${f}
# cat attachment
cat /tmp/${f}.msg | mail -s "Logs $(date +%m%d%Y)" my@email.dk
# remove crap
rm -f /tmp/${f}.msg /tmp/${f}
# exit w status of last action
exit $?

...saves 3 crontab entries.

..another way is to let logrotate handle it, add a "prerotate" section to the file, for example messages:

[/code]
#/etc/logrotate.d/boot.log
# add:
prerotate
cat /var/log/boot.log | mail -s "Boot.log $(date +%m%d%Y)" my@email.dk
endscript
# on with the usual stuff:
size=50M
yearly
rotate 30000
[/code]

Virtus 01-21-2003 03:43 AM

Thanks alot unSpawn.
I get a few errors with your script thoug..
This is how far i gotten..


<snip sendlog.sh>
f=cron.$(date +%m%d%Y).tgz
# make a tarball
tar -czf /tmp/${f} /var/log/messages
# make attachment
makemime -c -N "${f}" -o /tmp/${f}.msg /tmp/${f}
# cat attachment
cat /tmp/${f}.msg | mail -s "Logs $(date +%m%d%Y)" my@email.dk
# remove crap
rm -f /tmp/${f}.msg /tmp/${f}
# exit w status of last action
exit $?
</snip sendlog.sh>

Then i run a
[root@ns1 cron.scripts]# ./sendlog.sh
tar: Removing leading `/' from member names
[root@ns1 cron.scripts]#

Then i get a email with
<email>
Content-Type: application/octet-stream; name="cron.01212003.tgz"
Content-Transfer-Encoding: base64

H4sIAIEVLT4AA+3U3UrDMBQH8F77FAe82HaTnaRpuwbEe19hiFQbZ3FtRtJu7u3NHLsponixyeD/
I9DSHM7JV7Ot/HztVvPWhlCtbEjOgCVzzpzw0fgplZQJF7lMFRey0DFe5ZlKiM8xmLEh9JUnSrxz
/U9xv/VfqYeqIyWJtWEVG3VBUtiHeCRqkkILacjbwxL14uYUWxqlTKq/YruqtfWyyLJHQ+v4TsH6
rfXkOprsdjvx4trN0FsfqvVK1O8TmjaxZ/z1fmZIlplQuhSaRXabpZerpkfVUqMXl5vbeauN5qa1
kcVxj8NbPd1U7dPQNR+zZVkWZawb4i3QxIJuYztb06vzNMRh0OHw0/OepkNT3/HslFGyiU3xdxkl
q3zxh5T//SMAAAAAAAAAAAAAAAAAAAAAAFyhTy8X47cAKAAA
</email>

Is this correct ?? i thoug it would attach a file with the zipped log so i could extract it.. ?!?

Virtus.

unSpawn 01-31-2003 07:18 AM

Naw, the output from tar is just a warning, devnull it.
Any decent MUA can save MIME attachments, should be no problem.


All times are GMT -5. The time now is 12:25 PM.