Sponsored Content
Top Forums Shell Programming and Scripting [Shell/Perl(?)] Prepending timestamps to console output & writing results to a file Post 302646965 by Vryali on Saturday 26th of May 2012 03:16:42 PM
Old 05-26-2012
[SOLVED] [Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :]

By default, the output of TSM's console has no timestamping, making it hard to sort through accurately.

This puts my console into a file continously:

Code:
${DSMPath} -id=${TivUser} -password=${TivPassword} -console 1>/tmp/out.file 2>&1 &

That works, no problems there. The log looks like this:

Code:
IBM Tivoli Storage Manager
Command Line Administrative Interface - Version 6, Release 2, Level 1.0
(c) Copyright by IBM Corporation and other(s) 1990, 2010. All Rights Reserved.

Session established with server TSM1_TIVOLI1: AIX
  Server Version 6, Release 2, Level 2.0
  Server date/time: 05/26/12   15:06:16  Last access: 05/26/12   15:00:00

ANR1041I Space reclamation ended for volume NC0657L3.
ANR0568W Session 76132 for admin XXX (AIX) terminated - connection with client severed.
ANR8216W The server experienced a TCP/IP error while sending data on socket 176.  Reason 32.
ANR1040I Space reclamation started for volume 1988AFL3, storage pool TAPEPOOL (process number 1276).
ANR1044I Removable volume 1988AFL3 is required for space reclamation.
ANR1176I Moving data for collocation set 1 of 1 on volume 1988AFL3.
ANR0515I Process 1276 closed volume 1422AFL3.
ANR0407I Session 76170 started for administrator XXX (AIX) (Tcp/Ip tivoli2(58522)).
ANR2017I Administrator XXX issued command: QUERY MOUNT
ANR8330I LTO volume 2126AFL3 is mounted R/W in drive DRIVE08 (/dev/rmt8), status: IN USE.
ANR8330I LTO volume 004AAFL3 is mounted R/W in drive DRIVE04 (/dev/rmt4), status: IN USE.
ANR8329I LTO volume NC0657L3 is mounted R/O in drive DRIVE02 (/dev/rmt2), status: IDLE.
ANR8330I LTO volume 1782AFL3 is mounted R/O in drive DRIVE06 (/dev/rmt6), status: IN USE.
ANR8330I LTO volume 1639AFL3 is mounted R/W in drive DRIVE09 (/dev/rmt9), status: IN USE.
ANR8330I LTO volume 011AAFL3 is mounted R/W in drive DRIVE11 (/dev/rmt11), status: IN USE.
ANR8330I LTO volume 2095AFL3 is mounted R/W in drive DRIVE07 (/dev/rmt7), status: IN USE.
ANR8330I LTO volume NC0377L3 is mounted R/W in drive DRIVE12 (/dev/rmt12), status: IN USE.
ANR8329I LTO volume 1422AFL3 is mounted R/W in drive DRIVE05 (/dev/rmt5), status: IDLE.
ANR8330I LTO volume 948AAFL3 is mounted R/W in drive DRIVE10 (/dev/rmt10), status: IN USE.
ANR8330I LTO volume 052AAFL3 is mounted R/O in drive DRIVE03 (/dev/rmt3), status: IN USE.
ANR8376I Mount point reserved in device class LTO2DEVCLASS, status: RESERVED.
ANR8379I Mount point in device class LTO2DEVCLASS is waiting for the volume mount to complete, status: WAITING FOR VOLUME.
ANR8334I         13 matches found.

The following snippet works - to my screen, and I can't for the life of me get it to output to a file. I know tail -f mucks with my ability to continue piping, but my attempts at adding a file handle to my perl print to output there all failed miserably (I'm very bad/novice level with perl).

Code:
tail -f /tmp/out.file | perl -pne '@tm = localtime; printf ("%02d:%02d:%02d ",@tm[2],@tm[1],@tm[0]);

On my screen - it looks like this now (Which is as intended):
Code:
15:06:20 IBM Tivoli Storage Manager
15:06:20 Command Line Administrative Interface - Version 6, Release 2, Level 1.0
15:06:20 (c) Copyright by IBM Corporation and other(s) 1990, 2010. All Rights Reserved.
15:06:20
15:06:23 Session established with server TSM1_TIVOLI1: AIX
15:06:23   Server Version 6, Release 2, Level 2.0
15:06:23   Server date/time: 05/26/12   15:06:16  Last access: 05/26/12   15:00:00
15:06:23
15:06:23 ANR0515I Process 1276 closed volume NC0657L3.
15:06:23 ANR8216W The server experienced a TCP/IP error while sending data on socket 176.  Reason 32.
15:06:23 ANR1041I Space reclamation ended for volume NC0657L3.
15:06:23 ANR0568W Session 76132 for admin XXX (AIX) terminated - connection with client severed.
15:06:23 ANR8216W The server experienced a TCP/IP error while sending data on socket 176.  Reason 32.
15:06:23 ANR1040I Space reclamation started for volume 1988AFL3, storage pool TAPEPOOL (process number 1276).
15:06:23 ANR1044I Removable volume 1988AFL3 is required for space reclamation.
15:06:23 ANR1176I Moving data for collocation set 1 of 1 on volume 1988AFL3.
15:06:26 ANR0515I Process 1276 closed volume 1422AFL3.
15:06:28 ANR0407I Session 76170 started for administrator TIPADMIN (AIX) (Tcp/Ip tivoli2(58522)).
15:06:28 ANR2017I Administrator XXX issued command: QUERY MOUNT
15:06:28 ANR8330I LTO volume 2126AFL3 is mounted R/W in drive DRIVE08 (/dev/rmt8), status: IN USE.
15:06:28 ANR8330I LTO volume 004AAFL3 is mounted R/W in drive DRIVE04 (/dev/rmt4), status: IN USE.
15:06:28 ANR8329I LTO volume NC0657L3 is mounted R/O in drive DRIVE02 (/dev/rmt2), status: IDLE.
15:06:28 ANR8330I LTO volume 1782AFL3 is mounted R/O in drive DRIVE06 (/dev/rmt6), status: IN USE.

Would dearly appreciate any help - I'm pretty sure the right answer is to get the print statement going to a file, but I'm just having zero luck. If I do -not- have the right answer, I don't care how I get there, but the above is what I want (Just going to keep 7 files with the days of the weeks worth of console logs, nothing super complicated).

Version Info:
Perl
Code:
$ perl -v

This is perl, v5.8.8 built for aix-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

AIX
Code:
# oslevel -s
6100-04-03-1009

Thanks for your time and any help that can be provided.

Last edited by Vryali; 05-26-2012 at 07:01 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding pattern & prepending a line with text

Hello Dudes, I have a task to make a unix shell script that should search for a specific TEXT in a file.If that TEXT is found, shell script should add a comment statement before that TEXT line. Ex : LINE 1 xxxxx LINE 2 xxxx CALL xxxx LINE 3 xxxx PERFORM UNTIL if i... (1 Reply)
Discussion started by: kirrushna
1 Replies

2. UNIX for Dummies Questions & Answers

Writing to a file without echo it to the console !!!!

hi all, I am trying to write some message to a file using the following command. echo "${MESSAGE}" >&1 | tee -a ${File_name} can the same be done without using echo . I don't want the result to be displayed to the console. Can anyone guide me. Thanks in advance (6 Replies)
Discussion started by: amit_kv1983
6 Replies

3. Shell Programming and Scripting

Writing sql results to file using ksh -nevermind

I'm having problems with writing my sql results to a file: sqlplus -S username/password@DB <<!! set echo off set verify off set showmode off set feedback off set timing off set linesize 250 set wrap off set pagesize 0 set newpage none set tab off set trimspool on set colsep... (1 Reply)
Discussion started by: avillanueva
1 Replies

4. Shell Programming and Scripting

shell script output in HTML or with table like results

Hello, Currently i have a ksh script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html or excel format and send that content as email. Please help me how i can do... (2 Replies)
Discussion started by: kotasateesh
2 Replies

5. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

6. Shell Programming and Scripting

Perl - save results to output file.

Can any one please help, the code works...I want the output of $result to be saved in an output.txt file which is lcoated in c:\\temp\\output.txt. $filepath="C:\\temp\\ip.txt"; open (HOSTLIST,"$filepath"); @hosts=(<HOSTLIST>); foreach $host(@hosts) { $results = `nslookup... (1 Reply)
Discussion started by: sureshcisco
1 Replies

7. Shell Programming and Scripting

Sed script for appending & prepending

Hello Mates I am trying to write a script, which appends and prepends the text in a file. I tried testing with a small file and it worked fine. but for the large file, the script is wiping the entire file and adds only the word to be appended in the file. mv $file_name $file_name.bak sed... (6 Replies)
Discussion started by: sathyaac
6 Replies

8. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

9. Shell Programming and Scripting

[Solved] Writing output to the console

Hi All, I have written one script in which am writting the result to the log file. I want to display the results on the console also if ; then echo "$result doesnot match with the host file">>InputHostsFileErrors.txt else echo "$result input matches with the host... (7 Replies)
Discussion started by: sharsour
7 Replies

10. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies
All times are GMT -4. The time now is 02:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy