Sponsored Content
Top Forums Shell Programming and Scripting Adding logging feature to ksh script? Post 302700441 by TAllison on Thursday 13th of September 2012 11:33:34 AM
Old 09-13-2012
Adding logging feature to ksh script?

Good morning all,

I have a ksh script that I would like to log all "Terminal" out to a log file. I have tried several different methods to no avail! Below is my script and any advice or assitance would be great! The script works great but can not figure out how to log all outputs to a log file.
Code:
###################################################################################
## Global Variables
###################################################################################
localHost=$(hostname)
env="Env"
project="EDR"
wmbversion="7.0"
brokerListFile=
brokerExGrpListFile=
queuelist=/var/mqm/scripts
IFS=","
JMSDIR=/usr/mqm/java/bin
wmbversion="7.0"
wmqversion="7.0"
wmbversion="7.0"
wmqversion="7.0"
scriptfiles="/downloads/APP_Software/IBM/wmq_wmb/scripts"
mqmvardir="/var/mqm"
mqmlogdir="/var/mqm/log"
mqmerrdir="/var/mqm/errors"
scriptdir="/var/mqm/scripts"
logdir="/opt/IBM/install_logs/wmq_wmb"
logfile="config.log"
LOG_FILE=/tmp/${0##*/}.log
_DEBUG="on"
##################################################################################
## Debug Function
##################################################################################
DEBUG()
{
[ "$_DEBUG" == "on" ] && $@ || :
}
##################################################################################
## Logging Function
##################################################################################
 
#####################################################################################
## Main Routine
#####################################################################################
main() {
DEBUG echo "Status: Entering Main Routine.. "
LogMsg *
createJMSEnv *
buildbrk *
DEBUG echo "Status: Exiting Main Routine.. "
}
LogMsg() {
 # Logging setup 
exec 3>$1 4>$2
trap 'exec 2>$4 1>$3' 0 1 2 3
exec 1>$LOG_FILE 2>$1
}
createJMSEnv() {
DEBUG echo "Status: Entering createJMSEnv.. " 
cd $JMSDIR
perl -p -i -e "s/file:\/C:\/JNDI-Directory/file:\/var\/mqm\/JNDI-Directory/g" JMSAdmin.config
cd $mqmvardir
mkdir -p JNDI-Directory
chmod 777 JNDI-Directory
cd $scriptdir
DEBUG echo "Status: Exiting createJMSEnv.. "
}
buildbrk() {
 
id=`whoami | awk '{ print $1 }`
if [ $id != "mqm" ]
then
   DEBUG echo "setting wmb environment for command execution"
   portNumber="1414"
   `su - mqm -c`
else
   mqsi=/opt/IBM/mqsi/$wmbversion/bin
   . $mqsi/mqsiprofile
   $mqsi/mqsicreatebroker $bkrname -q $qmname
   runmqsc $qmname <$queuelist/queuebuild.in 
   echo "DEFINE LISTENER($qmname.TCP) trptype(tcp) port(1414) control(qmgr)" | runmqsc $qmname
   echo "START LISTENER($qmname.TCP)" | runmqsc $qmname
   echo "DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) CHLTYPE(SVRCONN) TRPTYPE(TCP)" | runmqsc $qmname 
   wmb=`mqsilist -a |cut -d "'" -f2 |grep EDR`
   echo $wmb
   for i in $wmb
   do
      `mqsistart $i`
   done
fi
}
####################################################################################
## Entry Point
####################################################################################
#Checking environment variables
if [ ! "$1" ];
then
   DEBUG echo "Failure: You must provide the environment"
   DEBUG echo "exiting with value 1"
   exit 1
else
   qmname="${project}_$1_QM"
   bkrname="${project}_$1_BRK"
   DEBUG echo "Status: Queue Manager to create = $qmname"
   DEBUG echo "Status: Broker to create - $bkrname"
   DEBUG echo "Status: Calling Main Routine ... "
   main $*
   DEBUG echo "Exit: Exiting Main Routine and Terminating script ... "
   exit 0
fi

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 09-13-2012 at 12:44 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding entry into crontab in ksh program

Hi falks, I have the following ksh function ,which adding entry to crontab during ksh program running: { print "Go\c" >/dev/null 2>&1 print '0 0 * * * su - ias -c "/home/orca/core-${SCHEMA_NAME}/CLI/cleanup_BRMS.ksh"\c' >/dev/null 2>&1 print "\033:wq!" >/dev/null 2>&1 } | \crontab -e... (2 Replies)
Discussion started by: nir_s
2 Replies

2. Shell Programming and Scripting

Adding array element in KSH

All, I would like to add the first 10 elements of an array. Here is how I am doing it now (only included first few add ops): #!/usr/bin/ksh ###Grab the array values out of a file### TOTAL=`awk '/time/' /tmp/file.out | awk '{print $4}'` set -A times $TOTAL SUM=$((${times} + times... (3 Replies)
Discussion started by: Shoeless_Mike
3 Replies

3. Shell Programming and Scripting

ksh - adding a dynamic value to the front of a line

Hi Forum, Im trying to write some code to read a file, take a certain dynamic value and write it back to the file at the front of every line. For example, file.txt is: SIMPLE=HELLO CONFIDENTIAL=false SENDER=false REQUIRED=true FEEDBACK=false UPDATE=false REQUIRED=false MAPPING=true... (9 Replies)
Discussion started by: ocelot
9 Replies

4. Shell Programming and Scripting

Help with adding logging to a script

I'm pretty new to bash shell scripting and I was wondering how to add some logging to a script?:confused: (2 Replies)
Discussion started by: kp400sf
2 Replies

5. Shell Programming and Scripting

ksh - find command with 2 actions attached and error logging

Hi there, I'm encountering problems on an AIX system when using following in my script. find . -name *.edi -type f -exec sh -c 'scp {} $user@$server:$path || exit 5; mv {} $sent || exit 7' \; the error i get is following find: 0652-018 An expression term lacks a required... (4 Replies)
Discussion started by: Kerberos
4 Replies

6. Shell Programming and Scripting

Need a ksh script for adding the space at the end of record in a flat file

Hi, I need a ksh script for the below requirement: i have a Delimited flat file with 200 records delimiter is '|~|' i need a script to insert space at the end if the record is ending with delimiter '|~|' if it didnt end with delimiter it should not append space. Example: ram|~|2|~| ... (16 Replies)
Discussion started by: srikanth_sagi
16 Replies

7. Shell Programming and Scripting

[Solved] adding email option to KSH

Hi, I wanted to add a email option to this script. and was wondering if anyone could help me out. #!/bin/ksh echo "Finding hdisk" <DIR>/find-disk i=1 b=0 p=0 while ... (2 Replies)
Discussion started by: vpundit
2 Replies

8. UNIX for Beginners Questions & Answers

ksh Logging

Hi, I want to run my script and want to ensure it captures all logging. For e.g I got this from another forum # Redirect the current stderr into stdout exec 2>&1 # Redirect the current stdout into the log file exec 1>timer_log.log The script will print stderr onto the putty terminal... (4 Replies)
Discussion started by: aixkidbee
4 Replies

9. UNIX for Beginners Questions & Answers

To send ID and Password for each command using expect feature in bash script

Dear Tech Guys, I am trying to send some commands on the local server and it always asks for user name and password after each command. To serve the purpose I am using expect function as follows: #!/usr/bin/expect set timeout 20 spawn "./data1.sh" expect "Please Enter UserName: "... (6 Replies)
Discussion started by: Xtreme
6 Replies
All times are GMT -4. The time now is 10:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy