Shell Script for GC Logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script for GC Logs
# 1  
Old 09-29-2011
MySQL 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.
# 2  
Old 09-29-2011
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:
Code:
 java ... -Xloggc:/path/gc-$(date +%Y%m%d-%H%M%S).log ...

# 3  
Old 09-29-2011
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
# 4  
Old 09-30-2011
Quote:
Originally Posted by Neeryan
then the file will be again overwritten isn't?
What would the file be overwritten ? Perhaps do you mean appended to ?
Quote:
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.
What service ? What problem ? I'm missing to understand your objections.
# 5  
Old 09-30-2011
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
# 6  
Old 09-30-2011
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.
# 7  
Old 10-01-2011
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Shell script for capturing FTP logs

I have a script #!/bin/bash HOST=ftp.example.com USER=ftpuser PASSWORD=P@ssw0rd ftp -inv $HOST <<EOF user $USER $PASSWORD cd /path/to/file mput *.html bye EOF the script executes sucessfully I need to capture the FTP logs to a logfile should contain FTP Login successful ... (1 Reply)
Discussion started by: rajeshas83
1 Replies

3. Shell Programming and Scripting

Help with Shell Script to View Logs

Hi I'm very new to unix shell scripting. Im also new here in this forum. I'm a SQL Server DBA but I'm slowly learning Oracle and Sybase DB. Our Oracle and Sybase are on Unix platforms. Im slowly learning Linux Admin and Shell Scripting to automate tasks. I'm writing a script to view DB error... (4 Replies)
Discussion started by: Ricky777
4 Replies

4. Shell Programming and Scripting

Shell script - Asterisk logs report

Dear all, I start to build script(s) for few tasks, and I'll use log files to complete the following: 1) when ringnoanswer for a particular operator hits count 10 for waittime > 14000 send mail alert with summary of calls 2) per queue - exitwithtimout > 1 in any hour, then send mail... (12 Replies)
Discussion started by: bigbrobg
12 Replies

5. Shell Programming and Scripting

Managing logs in shell script

Hi, I need write a shell script which should be executed from the crontab every day. This shell script is running several other shell scripts , and each one of them is writing to its log file. Few of the the shell script are also connecting using ssh to some other users on remote machine , do... (1 Reply)
Discussion started by: Yoav
1 Replies

6. Shell Programming and Scripting

Help with extract application logs through shell script in performance testing

Hi Experts, I am new to shell.How to extract logs (Web,APP,Database) using shell in performance testing? Need for webserver logs,app server logs and d/b logs code. Thanks in advance Sree (3 Replies)
Discussion started by: sree vasu
3 Replies

7. Shell Programming and Scripting

shell script to grep 500 error messages from access logs

Hello Team, I need help to improve my script which is used to grep 500 error messages in the logs. I am using following logic in the script to grep 500 error messages in the logs. var1=`awk '$9 == "500"' access_log | tail -1` The above logic is not useful if logs are not getting... (1 Reply)
Discussion started by: coolguyamy
1 Replies

8. Shell Programming and Scripting

help with a shell script that greps an error from the logs

Hello everyone. I wrote the following script but the second part is not excecuting. It is not sending the notification by email if the error occurs. the send mail is working so i think the errorr should be in the if statement LOGDIR=/logs/out LOG=`date "+%Y%m%d"`.LOG-FILE.out #the log file ... (11 Replies)
Discussion started by: adak2010
11 Replies

9. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

10. Shell Programming and Scripting

Shell script to view logs of a server

Please share a shell script to collect logs of a server (like cpu utilization, memory etc) for a perticular time interval by giving date, time and server name as input. (1 Reply)
Discussion started by: abhishek27
1 Replies
Login or Register to Ask a Question