View Full Version : cron jobs and things
lucas
10-10-2002, 10:12 PM
has anyone set up cron jobs to backup logs? i have no idea how to begin. all the web seems to be good for is telling me how to setup when to run a cron job and not how to actually write the cron job itself. not to mention the log file location is kinda weird since it doesn't appear to be stored within my account.
Steven
10-12-2002, 11:36 AM
Hey Lucas,
Sorry I must have missed this post somewhere in the fray of things. What do you mean by cron job to backup logs? The logs file is located at /usr/local/apache/domlogs/yourdomain.com . So you would need to write a small script that is able to send a copy of these logs preferable to /home/username (as that is a non web accessible directory). All the cron does is executes the script/file at a time that you specify.
-Steven
lucas
10-12-2002, 11:47 AM
logs are deleted on the last day of the month at 11:59. if you want to back them up and compress them so you can view them with a 3rd party application then do this:
go to advanced > cron jobs
you see this:
http://extremesanity.com/misc/cronjob.gif
minute (0-59)
hour (0-23)
day(1-31)
month(1-12)
weekday(0-6) *sunday = 0
i use these two lines:
cp /usr/local/apache/domlogs/woodthatrocks.com /home/loginName/public_html/log/logged.txt
this copies the logs to a directory in your account. "log" is a folder i've created within my account, "logged.txt" is what the file will be saved as within that folder.
gzip /home/loginName/public_html/log/logged.txt
this line compresses the logs down substantially, a full month of logs can be several megabytes.
the first line to copy the logs is set to a time format of
50-23-31-*-* which says to the server to execute the cron job on the last day of each month, every month, at 11:50 pm.
the second line to compress the logs uses
55-23-31-*-* which says to execute the cron job at 11:55 pm on the last day of the month, every month.
lucas
10-12-2002, 11:48 AM
Originally posted by Steven
Hey Lucas,
Sorry I must have missed this post somewhere in the fray of things. What do you mean by cron job to backup logs? The logs file is located at /usr/local/apache/domlogs/yourdomain.com . So you would need to write a small script that is able to send a copy of these logs preferable to /home/username (as that is a non web accessible directory). All the cron does is executes the script/file at a time that you specify.
-Steven
yeah, i got it figured out with help from Tal, thanks.
harmonic
10-12-2002, 11:53 AM
try something like this:
<?
$domain = "yourdomain.com";
$destination = "/home/username"; // no slash at end
// stop editing
$name = date("m-Y").".bak";
copy("/usr/local/apache/domlogs/$domain", "$destination/$name");
?>
now just execute that, it should copy it... and it will name the logs like
01-2002.bak - january, 2002
02-2002.bak - february, 2002
etc...
lucas
10-12-2002, 01:44 PM
i know there is a way to do that with just the linux commands too but i haven't gotten that far yet. :banana
Just wanted to say great job Lucas. Doesn't it really feel good when you figure out something and are able to explain it to others? I know it does for me.
:cool:
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.