Sponsored Content
Top Forums Shell Programming and Scripting [Shell/Perl(?)] Prepending timestamps to console output & writing results to a file Post 302647071 by Vryali on Sunday 27th of May 2012 06:15:06 AM
Old 05-27-2012
Makes sense - I've bookmarked the other bit for reading when I'm more awake.

Wanted to come back and post my script, in case anyone had a use for them courtesy of the google machine later. There isn't a lot to it, and the hard part isn't mine per se, but here we go. Should work on any system with TSM server installed (Except Windows, but if you installed TSM on Windows, that's your own damn fault :])

Code:
#!/bin/sh
###############################################################################
#                                                                             #
#  Script Name: TSM-Console.sh                                                #
#  Created on : 05/26/2012                                                    #
#  Author     : Vryali                                                        #
#  Purpose    : Allow for console logging, which is normally more succint and #
#       easier to parse than the actlog, and keep seven days worth of logging.#
#  Note       : This script can be run through the crontab or AutoSys.        #
#  Cron                                                                       #
#       0 0 * * * /usr/local/bin/TSM-LogConsole.sh 1>/dev/null 2>&1           #
#  AutoSys/JIL                                                                #
#   insert_job: SA.TSM.LogConsole                                             #
#   command: /jobs/SA/prod/Prod_Run tsm@tivoli /usr/local/bin/TSM-Console.sh  #
#   permission: gx,wx                                                         #
#   date_conditions: 1                                                        #
#   days_of_week: all                                                         #
#   start_times: "00:01"                                                      #
#   description: "TSM Console Logging Script"                                 #
#   alarm_if_fail: 1                                                          #
#                                                                             #
#  History:                                                                   #
#  00 : Vryali     05/21/2012                                                 #
#       Original version of the script completed.                             #
#                                                                             #
###############################################################################

DSM="/usr/bin/dsmadmc"
TSMUser="username"
TSMPass="password"
PIDFile="/var/run/tsmconsole.pid"
CONLOG="/TSM/home/CONSOLE_LOG/`date +%a`-Console.log"

if [ -s ${PIDFile} ]; then
    cat ${PIDFile} | xargs kill -9
    cp /dev/null ${PIDFile}
fi

# Clear up the old one [if needed] but keep permissions...
cp /dev/null ${CONLOG}

# Start logging
nohup ${DSM} -id=${TSMUser} -pass=${TSMPass} -console| awk 'BEGIN { c = "date \"+%D %T\""; } { m=$0; c | getline; close( c ); print $0, m; }' >> ${CONLOG} 2>&1 &
# $! is actually awk - not DSM, so we'll filter out $$ - which is the subshell before we exit it.
ps -ef| grep $! | grep -v grep | grep -v $$ | awk '{print $2}' > ${PIDFile}
exit 0


Last edited by Vryali; 05-27-2012 at 07:21 AM.. Reason: Forgot to remove real name :)
 

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
smcwebserver(1M)					  System Administration Commands					  smcwebserver(1M)

NAME
smcwebserver - manage the server for the Sun Web Console SYNOPSIS
/usr/sbin/smcwebserver subcommand options DESCRIPTION
The smcwebserver utility manages the Sun Web Console server. Sun Web Console is a browser-based interface that performs systems management. System administrators can manage systems, devices and services from the console. When the console webserver is running, you can view the console by opening a browser and pointing to: https://host:6789 host is the machine where the console has been installed and the console server is running. SUBCOMMANDS
The following subcommands are supported: disable Disable automatic start or stop during system boot or shutdown. Until the administrator reruns the script with the smcweb- server enable subcommand the webserver can be started/stopped only when the administrator executes the script manually using the following command: # /usr/sbin/smcwebserver [start | stop] enable Enable the webserver to startup automatically during subsequent system boot and gracefully stop during system shutdown. restart Stop and subsequently start the console webserver. The format of the restart subcommand is: restart [-U username] start Start the console webserver. The format of the start subcommand is: start [-U username] stop Stop the console webserver. status Display status of the console webserver. The format of the status subcommand is: status [-p] OPTIONS
The following options are supported: -U username | --username usernamThe user identity to run the server as. Once the server has successfuly started under the specified iden- tity, all subsequent starts will automatically be done under that identity until you change it via this option, or by changing the com.sun.web.console.user configuration property via the smreg(1M) command. The default is to run the server under the "noaccess" identity. -p | --parseable Display non-localized output suitable for programmatic parsing. If the server is running, the output will be: running=yes If the server is not running, the output will be: running=no -h | --help | -? Display the usage statement. -V | --version Display console version information. EXAMPLES
Example 1: Displaying the Usage Statement The following command displays the smcwebserver usage statement: % smcwebserver --help Example 2: Determining if the Server is Running The following shell command will start the server if it is not already running. ans=`smcwebserver -p | grep running | cut -d"=" -f2` if [ "$ans" = "no" ]; then smcwebserver start fi ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of smcwebserver: JAVA_HOME If you do not specify this environment variable, your PATH is searched for a suitable java. Otherwise, depending on the OS, the follow- ing default locations are used: Solaris: /usr/j2se Linux: /usr/java/j2sdk1.4* EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWmcon | +-----------------------------+-----------------------------+ SEE ALSO
smreg(1M), attributes(5), environ(5) SunOS 5.10 27 May 2004 smcwebserver(1M)
All times are GMT -4. The time now is 09:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy