LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-17-2003, 05:25 AM   #1
Virtus
Newbie
 
Registered: Jan 2003
Location: Denmark
Distribution: Redhat 8.0
Posts: 14

Rep: Reputation: 0
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.
 
Old 01-17-2003, 09:08 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594
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]
 
Old 01-21-2003, 03:43 AM   #3
Virtus
Newbie
 
Registered: Jan 2003
Location: Denmark
Distribution: Redhat 8.0
Posts: 14

Original Poster
Rep: Reputation: 0
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.
 
Old 01-31-2003, 07:18 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cronjob help meeh Linux - General 1 03-26-2004 11:41 AM
Cronjob engnet Linux - Networking 6 03-03-2004 09:21 AM
cronjob ugob Linux - Software 0 03-03-2004 09:20 AM
Su in a cronjob michedlp Programming 3 11-06-2003 08:30 AM
cronjob FastEddy Linux - General 1 04-12-2003 09:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration