Shell script to append a time for the existing error log file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Shell script to append a time for the existing error log file
# 1  
Old 07-06-2007
Shell script to append a time for the existing error log file

Hi Guys,

the requirement is like this,
i am having a error log file in this format,


[INFO ][memory ] 4594.493: parallel nursery GC 2594592K->2544691K (2969600K), 30.848 ms
[INFO ][memory ] 4605.958: parallel nursery GC 2634887K->2584986K (2969600K), 38.900 ms
[INFO ][memory ] 4619.079: parallel nursery GC 2822555K->2774812K (2969600K), 51.526 ms
[INFO ][memory ] 4623.784: parallel nursery GC 2911872K->2862488K (2969600K), 43.049 ms
[INFO ][memory ] 4634.298: parallel nursery GC 2964037K->2915007K (2969600K), 44.723 ms
[INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms
[INFO ][memory ] 4657.312: parallel nursery GC 843925K->792192K (2969600K), 59.318 ms
[INFO ][memory ] 4667.661: parallel nursery GC 1023736K->973165K (2969600K), 54.639 ms
[INFO ][memory ] 4683.479: parallel nursery GC 1079790K->1028927K (2969600K), 57.430 ms
[INFO ][memory ] 4703.120: parallel nursery GC 1155728K->1104405K (2969600K), 48.580 ms
[INFO ][memory ] 4721.076: parallel nursery GC 1381399K->1331594K (2969600K), 67.131 ms
[INFO ][memory ] 4733.124: parallel nursery GC 1615502K->1565673K (2969600K), 67.668 ms
[INFO ][memory ] 4735.932: parallel nursery GC 1868345K->1818182K (2969600K), 60.527 ms
[INFO ][memory ] 4740.485: parallel nursery GC 1904639K->1852524K (2969600K), 39.426 ms
[INFO ][memory ] 4748.902: parallel nursery GC 1931641K->1880332K (2969600K), 45.826 ms
[INFO ][memory ] 4749.369: parallel nursery GC 1992582K->1939949K (2969600K), 40.806 ms
[INFO ][memory ] 4754.434: parallel nursery GC 2180168K->2130041K (2969600K), 49.643 ms
[INFO ][memory ] 4773.739: parallel nursery GC 2184441K->2132628K (2969600K), 47.404 ms
[INFO ][memory ] 4793.466: parallel nursery GC 2488886K->2439957K (2969600K), 65.046 ms
[INFO ][memory ] 4825.436: parallel nursery GC 2539740K->2489040K (2969600K), 57.110 ms
[INFO ][memory ] 4829.277: parallel nursery GC 2668261K->2617286K (2969600K), 44.117 ms
[INFO ][memory ] 4835.849: parallel nursery GC 2671686K->2619201K (2969600K), 37.932 ms
[INFO ][memory ] 4849.233: parallel nursery GC 2781360K->2730476K (2969600K), 47.521 ms
[INFO ][memory ] 4870.198: parallel nursery GC 2902826K->2851834K (2969600K), 56.248 ms
[INFO ][memory ] 4873.277-4874.744: GC 2947600K->754541K (2969600K), 1467.026 ms
[INFO ][memory ] 4876.460: parallel nursery GC 824428K->769741K (2969600K), 146.708 ms
[INFO ][memory ] 4888.450: parallel nursery GC 916812K->862855K (2969600K), 46.349 ms
[INFO ][memory ] 4902.871: parallel nursery GC 992190K->936997K (2969600K), 30.377 ms
[INFO ][memory ] 4907.508: parallel nursery GC 1167917K->1115851K (2969600K), 63.247 ms
[INFO ][memory ] 4933.191: parallel nursery GC 1293112K->1239053K (2969600K), 51.764 ms
[INFO ][memory ] 4939.716: parallel nursery GC 1339610K->1284920K (2969600K), 41.355 ms



this file will go on displaying all the nursery GC, only 'GC'.



the main aim is that , error log file goes on generating output from weblogic as shown above, we want to take the timespan between two GC's

i.e
[INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms


so i want a script to append time at the end of the line i.e after 'ms'



so will anyone help me out with a script for the above requirement
(atleast suggestions are welcomed)
# 2  
Old 07-06-2007
Which time you want to append? Can you show the output required?
# 3  
Old 07-06-2007
[INFO ][memory ] 4634.298: parallel nursery GC 2964037K->2915007K (2969600K), 44.723 ms
[INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms
[INFO ][memory ] 4657.312: parallel nursery GC 843925K->792192K (2969600K), 59.318 ms


so here one thing to know is :

main GC = [INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms

nursery GC= [INFO ][memory ] 4657.312: parallel nursery GC 843925K->792192K (2969600K), 59.318 ms


so i want to append time to the above data, and the output should be:

[INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms 23:19:32 2007


i.e at the end of the above line it is appended by time as 23:19:32 2007
# 4  
Old 07-06-2007
i had written a script ,

tail -f /filers/f08-perf01/logFiles/wcluster/websites01-perf-1-8901/NodeManagerLogs/cobaltgroup_websites01-perf-1-8901/websites01-perf-1-8901_error.log |grep -v nursery > /home/readonly/g2
date "+%H:%M:%S" >> /home/readonly/g2
cat /home/readonly/g2


or
cd /filers/f08-perf01/logFiles/wcluster/websites01-perf-1-8901/NodeManagerLogs/cobaltgroup_websites01-perf-1-8901/
v1=`tail -f websites01-perf-1-8901_error.log|grep -ivn 'nursery'`
v2=`date "+%H:%M:%S"`
echo $v1 $v2


given executable permission to the file also, but still unable to print the output as
[INFO ][memory ] 4642.754-4644.124: GC 2969600K->745408K (2969600K), 1369.515 ms 23:19:32 2007
# 5  
Old 07-06-2007
Code:
awk -v var="23:19:32 2007" ' !/parallel nursery GC/ && /GC/ { $0=$0 " " var } ; 1' filename

# 6  
Old 07-06-2007
awk -v var="23:19:32 2007" ' !/parallel nursery GC/ && /GC/ { $0=$0 " " var } ; 1' filename

here in place of 23:19:32 2007 it should be replaced by system time
that is by making use of date command
# 7  
Old 07-06-2007
also it will be better if u explain ur script,
as i am not much familiar with awk script
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script to append double quotes for each column in a file

Hi Experts, I am beginner to the shell scripting, My requirement is to append double quotes for each column in a file if double quotes does not exist. Example: "abc"|123|"gh-ch"|23.067 Use code tags, thanks. (10 Replies)
Discussion started by: spidy
10 Replies

2. Shell Programming and Scripting

Append date to sql*plus spool (log) file in shell script

SQL*Plus version : 11.2.0.4 OS : Oracle Linux 6.5 SQL*Plus is a client application to connect to oracle database. The log file for this tool is generated via spool command as shown below. I am trying to append date ( $dateString ) to spool file as shown below. $ cat test2.sh #!/bin/bash... (4 Replies)
Discussion started by: kraljic
4 Replies

3. Shell Programming and Scripting

Shell Script | Parse log file after a given date and time stamp

I am developing one script which will take log file name, output file name, date, hour and minute as an argument and based on these inputs, the script will scan and capture all the error(s) that have been triggered from a given time. Example: script should capture all the error after 13:50 on Jan... (2 Replies)
Discussion started by: ROMA3
2 Replies

4. Shell Programming and Scripting

Append files to a existing tar file.

Hi all, I want to check whether tar file exists in the directory or not. If tar file exists in the directory then I want to append the files to it. I am using the below command to tar files if the file does not exist. tar zcvf <tar file name> <Files to append> However, if want to... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

5. Shell Programming and Scripting

How to append value at first line of CSV file using shell script?

I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line. Have a look and suggest, (7 Replies)
Discussion started by: anujrichhariya
7 Replies

6. Shell Programming and Scripting

append existing file with zeroes bsed on position

Hi i am trying to append value with 0 to an existing file in the position 50-56 & 58-64 only where empty space is there Rule: 1 row already has some value and i do not want to change anything for this row. 2nd record below you see the position 50-64 is empty, i want to replace with 0000000... (3 Replies)
Discussion started by: kshuser
3 Replies

7. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

8. Shell Programming and Scripting

shell script not getting current error messages with time from alert.log

Hi All, I need to get current error messages with time from alert.log.Below is my shell script but it's not working to meet this objective. could anyone pls share on the above issue for resolution: #################################################################### ## ckalertlog.sh ##... (2 Replies)
Discussion started by: a1_win
2 Replies

9. UNIX for Dummies Questions & Answers

Inserting Date&Time Stamp In Existing Log File

I am trying to insert a line with a date stamp in a file that is used to monitor activity in one of our directories. By doing this, I want to grep that file each day and go to the last entry for each time a error occurred and pull all errors generated if any exist. If error exists I want that error... (3 Replies)
Discussion started by: shephardfamily
3 Replies

10. Shell Programming and Scripting

script to run shell command and insert results to existing xml file

Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will 1. execute 'df -k' and return the volume names with specific text 2. surround each line of the above results in opening and closing xml tags 3. insert the results of step... (5 Replies)
Discussion started by: littlejon
5 Replies
Login or Register to Ask a Question