Cron Help

Status
Not open for further replies.

MajorHertz

Baseband Member
Messages
32
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?
 
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
 
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?
 
yes

though you may want to put these commands into a script, rather than put them all into crontab
 
What type of script do you recommend? just a shell script or in the .bash_profile or something more like a perl script?
 
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
 
yea right now I only have a handful of commands in there but I will put it into a script.

Thanks.
 
Status
Not open for further replies.
Back
Top Bottom