Shell Script for GC Logs

Hi,

I have a strange situation here, I want to archive gc.logs file, generated by a java application, the strange thing about gc.log file is is doesn't have any time/date stamp appended to it unlike other logs (catalina/access/error) and one more strange thing is when ever the application is restarted, the gc.logs are wiped out, now my requirement is I want to archive these gc.logs file on daily basis or if more frequently hourly basis. I have the script to archive the file based on the file name (for ex date appended to it) but how to archive gc.log file and based on what?

java gc files are created as gc.logs and if archive it for today, then the other day when the cron job will run it will overwrite the file.

Please suggest some script for this, one idea is to append the date to this file, but I am not able to understand how to do it.

Any help in this regards is appreciated.

Neeryan.

Just configure your application to create a log including a timestamp. That would give you the start time so you'll be a ble to know at what time the log events, which are timestamped with a delta from the JVM start, occur. This will also prevent the log to be overwritten when the JVM restarts.

Use something like:

 java ... -Xloggc:/path/gc-$(date +%Y%m%d-%H%M%S).log ...

Thanks for swift reply, a good suggestion, now the catch is..this will only give the time/date stamp when the service is restarted, lets say service is restarted today at some time, using the above parameter, it will generate a log file with today's date appended to it, also lets say..if I will run my cron job on daily basis, then the file will be again overwritten isn't?

The above suggestion could have helped in a scenario where a service is restarted on daily basis, but where service is not restarted daily, this will create problem for the service itself.

so this really..doesn't help to much extent. Any other suggestion or idea will be appreciated.

Thanks,
Neeryan

What would the file be overwritten ? Perhaps do you mean appended to ?

What service ? What problem ? I'm missing to understand your objections.

ok, let me explain it to you.

Lets say I have created a gc file in the format you suggested,
java ... -Xloggc:/path/gc-$(date +%Y%m%d-%H%M%S).log
This will identify when the log file started getting created, no problems till this point, now I want to archive this log file on daily basis, now the point to be considered is I am not going to restart the application everyday, so the gc log file will keep on getting written to the same date log file, isn't? (I guess you will agree), there is a cron job running which will archive the file everyday, lets consider today's date, we restarted the application, so the name of the log file will be somewhat like gc20110930.log, I want to archive it today at 23:59 PM done, now for tomorrow as the application has not been restarted, the gc logs will be written on the same log file gc20110930.log, tomorrow a cronjob runs again at 23:59 PM and the cron job will find the file with same name, it will archive the file in the same archive directory and as the name of the file is same available at the archive directory, it will overwrite the file, isn't? so just making the change in the name of the log file will not work.

Hope this helps.

Neeryan

I provided a method for the gc logs not to be lost when the jvm restarts which is the main (and I thought the only) issue you were complaining of.
With this solution, your backup script will overwrite a file with its own content, you won't lose anything.
If you want to store daily and hourly logs, just split the gc log files according to your needs in your backup script.

Ok, I got it, now I understood that, the log files were not lost as every time the JVM will restart, it will create a new logfile with the name which includes its date.

I will now check my backup script.

Thanks for clarification.

Neeryan