Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 12-10-2005, 02:28 PM   #1 (permalink)
 
Newb Techie

Join Date: Dec 2005

Posts: 32

MajorHertz

Default Cron Help

I'm running FC2 and have it running, in addition to many other things, my proxy server. It has DansGuardian running on top of squid. I know how to do the basic cronjobs and stuff but what I want to do is set at 11:58 each night to go to a logfile (access.log), grep it for the word "DENIED" and put those results in a text file named the date (i.e. mm.dd.yyyy). Right now I do it my hand by

grep DENIED access.log > mm.dd.yyyy
>access.log

where mm.dd.yyyy is 12.10.2005, etc. but want to automate this. How do I get it to automatically put in that day's date then run those commands?
MajorHertz is offline  
Old 12-10-2005, 03:14 PM   #2 (permalink)
 
Junior Techie

Join Date: Nov 2005

Posts: 74

philg

Default

as root type `crontab -e` and add a line to the file as follows
Code:
58 11 * * * grep DENIED access.log > `date +%m.%d.%Y` && >access.log
save the file and do a quick `crontab -l` to list the cron entries to make sure its saved right

EDIT: changed the command so that the month/day/year is in the correct order
philg is offline  
Old 12-10-2005, 03:26 PM   #3 (permalink)
 
Newb Techie

Join Date: Dec 2005

Posts: 32

MajorHertz

Default

Ok now if this file resides in a bizarre location (i.e. /opt/lampp/htdocs/guardian/access.log), and I want the dated file to reside in the same diectory, should I do a "cd" before the command?
MajorHertz is offline  
Old 12-10-2005, 03:43 PM   #4 (permalink)
 
Junior Techie

Join Date: Nov 2005

Posts: 74

philg

Default

yes

though you may want to put these commands into a script, rather than put them all into crontab
philg is offline  
Old 12-10-2005, 03:46 PM   #5 (permalink)
 
Newb Techie

Join Date: Dec 2005

Posts: 32

MajorHertz

Default

What type of script do you recommend? just a shell script or in the .bash_profile or something more like a perl script?
MajorHertz is offline  
Old 12-10-2005, 03:59 PM   #6 (permalink)
 
Junior Techie

Join Date: Nov 2005

Posts: 74

philg

Default

Just a simple shell script will do,

when you have many things in the crontab it will start to get cluttered if you have commands that wrap over many lines. So it makes sense to remove the commands, put them into a shell script and call the shell script in the crontab
philg is offline  
Old 12-10-2005, 04:01 PM   #7 (permalink)
 
Newb Techie

Join Date: Dec 2005

Posts: 32

MajorHertz

Default

yea right now I only have a handful of commands in there but I will put it into a script.

Thanks.
MajorHertz is offline  
 
Closed Thread

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On