Thursday Jan 10, 2008

Adding timestamp for each line in nohup.out

After reading Bernd's nice tip, I now remember one of our colleague posting question to internal support engineer alias:

  "How can I add timestamp to each line in nohup.out ?"

I didn't ask why the customer wanted to that. I thought customer was seeing intermittent output from JRE without any time&date info and they wanted to correspond those to real log files.

Anyway, now I know how to do it.

bash-3.00$ date
Fri Jan 11 00:38:52 JST 2008
bash-3.00$ nohup sh -c "iostat 5 2>&1 | nawk '{\\"date \\\\\\"+%m/%d/%Y %H:%M:%S\\\\\\":\\"|getline date;
close(\\"date \\\\\\"+%m/%d/%Y %H:%M:%S\\\\\\":\\");
printf (\\"%s %s\\n\\", date, \\$0)}'" &
[2] 30111
bash-3.00$ Sending output to nohup.out

bash-3.00$ tail -f nohup.out
01/11/2008 00:38:56: tty md0 md1 md2 md3 cpu
01/11/2008 00:38:56: tin tout kps tps serv kps tps serv kps tps serv kps tps serv us sy wt id
01/11/2008 00:38:56: 1 124 7 1 18 1 0 31 0 0 6 17 0 178 4 3 0 93
01/11/2008 00:39:01: 0 3 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 94
01/11/2008 00:39:06: 4 187 0 0 0 0 0 0 0 0 0 0 0 0 4 3 0 93
01/11/2008 00:39:11: 0 20 0 0 11 0 0 0 0 0 0 0 0 0 4 4 0 92
01/11/2008 00:39:16: 0 20 0 0 12 0 0 0 0 0 0 0 0 0 5 3 0 92

This may not work in non bash or for lot of other commands.
 

About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today