LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2006, 09:57 AM   #1
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Rep: Reputation: 30
Smile How to make a cron job


Hello

I have some custom log files that are getting very big. (36 MB and 87 MB respectively). I have some other log files, that came with my distro, that are switched every week so they are the regular log file and a compressed backup. I think the squid log is one of those. example: cache.log, cache.log.1.gz to cache.log.5.gz

I believe this is done with a cron job. How do I make a cron job to compress and backup my custom log files every day?

My custom log files are:
/var/log/squidGuard/badurls.log
/var/log/squidGuard/squidGuard.log

Thanks for the help.
 
Old 12-08-2006, 10:20 AM   #2
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
You could create a script and then drop it in cron daily, or manually edit the crontab and add the script.
 
Old 12-08-2006, 01:26 PM   #3
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Original Poster
Rep: Reputation: 30
Thanks for the reply. If you read the question, I need to know "HOW TO", not "what to".

In other words, I need a step by step guide to how to do what I am asking. What files I need to edit, what I need to type in, etc. That's why this question is in the newbie category, because I really don't know how to do it and never did it before.

I'm using Mandrake Multi Network Firewall with no GUI.
 
Old 12-08-2006, 03:48 PM   #4
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
You might check out the man pages for logrotate. I'm not sure on your distro, but on fedora core there is a directory /etc/logrotate.d/ that contains all of the config files. For example the squid file looks like this:

Code:
[root@dbox logrotate.d]# cat squid
/var/log/squid/access.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
}
/var/log/squid/cache.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
}

/var/log/squid/store.log {
    weekly
    rotate 5
    copytruncate
    compress
    notifempty
    missingok
# This script asks squid to rotate its logs on its own.
# Restarting squid is a long process and it is not worth
# doing it just to rotate logs
    postrotate
      /usr/sbin/squid -k rotate
    endscript
}
Most of the details for the config files can be found in the man pages for "logrotate". If you use /etc/logrotate.d/squid it should already be included in a cron job. However as I said before this is dependant on your distro. But it sounded like you have log rotation going on and all you need to do is add these files to the process.

Hope this helps,
Fordeck
 
Old 12-12-2006, 07:45 AM   #5
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Original Poster
Rep: Reputation: 30
hi fordeck,

Based on your reply I have edited /etc/logrotate.d/squid to add the following lines.

Code:
/var/log/squidGuard/badurls.log /var/log/squidGuard/squidGuard.log {
   weekly
   rotate 5
   copytruncate
   compress
   notifempty
   missingok
}
I just copied the same things that the squid logs have, since I basically want them to do the same thing. I did this last night and this morning the logs did not get backed up. Can you tell me what I did wrong?

Thanks.
 
Old 12-12-2006, 11:31 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Backed up? Or rotated?


Cheers,
Tink
 
Old 12-12-2006, 12:08 PM   #7
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Original Poster
Rep: Reputation: 30
Whatever the other ones do. You know, make a copy and compress it so it becomes logfile.log.1.gz and then start a new logfile.

Anyway, it didn't work.
 
Old 12-12-2006, 06:01 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
You'll need a shell script (called logrotate) like this:
Code:
#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
Check for a line in logrotate.conf like:

include /etc/logrotate.d

and you'll need a cron entry in /etc/crontab like so:
Code:
50 23 * * *       root    /path/to/logrotate
 
Old 12-19-2006, 09:55 AM   #9
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Original Poster
Rep: Reputation: 30
OK ummmmmmm

I didn't really understand that last post. I have the file /usr/sbin/logrotate, but when I opened it in vi it was a bunch of gibberish. I guess this means it's a binary file, anyway I can't read it.

I looked in /etc/logrotate.conf and it has the line you mentioned.

I looked in /etc/crontab but it did not have my squid stuff in there. I do not know how my squid logs are getting logrotated. But I want my squidguard stuff to do the same thing.
 
Old 12-29-2006, 09:16 AM   #10
Avatar
Member
 
Registered: May 2001
Location: Canada
Distribution: old ones
Posts: 538

Original Poster
Rep: Reputation: 30
help, my logs are still not getting rotated. Anyone?
 
Old 03-09-2007, 10:54 AM   #11
deoren
Member
 
Registered: Oct 2003
Location: USA
Distribution: Ubuntu
Posts: 216

Rep: Reputation: 30
Still having the 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job newbie_adm Linux - Newbie 2 06-05-2006 11:52 PM
How do I make a cron job run "every two weeks"? Seventh Linux - Newbie 12 01-13-2006 11:55 AM
how to make a simple code for just restarting Apache via a Cron job hsa Programming 1 08-22-2005 04:15 AM
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read efishta Linux - General 6 07-19-2003 10:03 PM
Cron Job imanahmadi Linux - Newbie 1 07-03-2003 11:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration