Forum Moderators: coopster & phranque

Message Too Old, No Replies

Need to Move or Rename Log Log File with Script

Server overwrites at month end before I can get it downloaded sometimes

         

The Toecutter

2:44 pm on Oct 1, 2002 (gmt 0)

10+ Year Member



I think I might be way over my head on this one because I know very little about PHP, Perl, or CGI but maybe there is a simple solution?

Anyway - here's my problem: At the end of the month my host starts a new log file by overwriting the existing one which causes all the prior month's data to be gone. I usually remember to download them before this happens but there has to be a better way!

QUESTION:
Is there a simple script out there I can use to rename (or copy to another subdirectory) my log file just before midnight at month's end?

Anyone else know another creative way to solve this problem?

Thanks!
John

Big_Balou

8:52 pm on Oct 1, 2002 (gmt 0)

10+ Year Member



I would be interested if anyone has a solution to this one as well. I download log files nightly but sometimes will miss out on the last day of the months logs if I forget.

<note>posted to bump this back up to the top...delete if neccesary</note>

Mark_A

9:01 pm on Oct 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What type of server do you have, apache servers offer an easy to apply logrotate procedure which can rotate logs as often as you like emailing you the oldest as a straight text email.

Should not affect any online stats as long as you configure them to create or keep history.

If you dont have an apache server I am sure there is a windows equivalent script.

Hope this helps.

Big_Balou

9:05 pm on Oct 1, 2002 (gmt 0)

10+ Year Member



Mark_A,

thanks. I'm on apache. Any links you can point me to that discuss this?

Mark_A

9:20 pm on Oct 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There will be loads of links in google about this plus search this site, probably been discussed in here before.

amoore

9:28 pm on Oct 1, 2002 (gmt 0)

10+ Year Member



redhat distributes a program called 'logrotate' that you can call to occasionally move your logs out of the way, compress, delete, or whatever them. You can call it from cron if you want. I wouldn't be surprised if this was already installed on your machine. It's probably in /usr/sbin or /usr/bin or /usr/local/bin.

Or, I can write you a shell or perl script to do it for you.Sticky me for more info.

The Toecutter

11:25 am on Oct 2, 2002 (gmt 0)

10+ Year Member



Mark_A:
Our server is running Apache.

amoore:
I cannot find any reference to "cron" in our help area on our host. I don't think we can run cron applications. We do not have directories "/usr/sbin or /usr/bin or /usr/local/bin"

Will the program 'logrotate' work from our cgi-bin directory? Our Apache server is configured to run PHP, Perl, etc.

Thanks for your leads.

John

PS - I stumbled across O'Reilley ONLamp.com. Seems like they may have some related info to the program Logrotate. I'll sticky you (amoore) if I can't solve it myself. Thanks!

Mark_A

11:40 am on Oct 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The Toecutter - Hi, it may be that you do not have full control of your server?

When you ftp in do you only see the directories where your web files exist or do you see the configuration directories as well.

Unless you have a dedicated or semi dedicated virtual server the hosting company may well have restricted you to running their or other scripts in the cgi bin in which case you will have to speak to your support people and ask them if what you want can be implemented.

Its not hard, if they cannot do this for you I would consider looking around for the future. You want more information available to you, in case you need it, not less.

The Toecutter

12:03 pm on Oct 2, 2002 (gmt 0)

10+ Year Member



Here are the directories listed when I ftp in:

bin, cert, cgi-bin, conf, httpdocs, httpsdocs, logs, pd, and web_users

I have just put a request into our helpdesk to ask about running cron jobs (I can't find anything about "cron" in the help files). I also asked them about Logrotate to see if they are familiar with it and asked them to suggest alternatives if it won't run on their servers.

The Control Panel says "Virtual host access for domain www.xxx.com" and "Virtual Host Type: IP-Based" and we have a static IP address.

John

Mark_A

12:28 pm on Oct 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



John I am no expert so I would probably get out of my depth trying to answer you. I would probe your tech support people about it, thats what you pay them for :-)

On my server logrorate was already installed and runs each day, (possibly by a tech admin's cron tab) all I have to do is configure what log files I want logrorate to run on, how often to rotate how many copies to keep and to whom I want the final rotated file to be emailed to.

BTW you may also want to look into initially configuring the log files you want in the virtual host statement for your site.

Hope this helps, someone with a clue will doubtless be along shortly :-)

The Toecutter

11:16 am on Oct 3, 2002 (gmt 0)

10+ Year Member



Here is the reply I received from our Help Desk:

You can run Cron jobs at our servers - just place cron-pretender script into one of Your FTP directories and submit appropriate helpdesk request, e.g. "add cronjob /cgi-bin/logreader.pl, should be initiated weekly".

Can anyone here point me to a simple script of some sort so I can begin to learn how to do this? I have seached here and at Google and cannot find a script file that will move, copy, email, or zip my log files so they do not get overwritten every month. Any help would be greatly appreciated!

Thanks,
John

jatar_k

4:47 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you need to move it? Otherwise you could just rename it to ensure that it isn't overwritten until you have the time to download it.

Someone here should be able to spit out a little file renamer in perl.

The Toecutter

5:30 pm on Oct 3, 2002 (gmt 0)

10+ Year Member



Renaming my server log file at 11:58 PM on a daily, weekly, or monthly period would work perfectly. Something simple (yeah right!)

Does anyone have a script that would serve this or a similar purpose?

Please sticky mail me. :)

TIA

Mark_A

6:32 pm on Oct 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



John I recon you should ask your support people straight, can they set up and configure logrotate on their server for you and other users or do you have to do it all yourself? if they cannot, can they tell you what do you need to do to set it up yourself.

If I needed to solve this myself I would probably first:
- search my hosting companies online help files,
- search the internet via google
- including search of apache's website
- probably also search this site
- bug my tech support until they told me what I needed to know

I am sure you are aware that many tech support peoples responses are not always designed to help you solve the problem, often they just seem to feed you a little tit bit of information in the hope that you might go away or solve it yourself :-) how much assistance is there in your server contract, do be sure you get your moneys worth and don't get fobbed off.

Hope this helps but to be more specific I would have to do it for you and I am too busy right now sorry mate :-)