Help with KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with KSH
# 1  
Old 01-20-2009
Help with KSH

Hi,

I need some help with the Ksh scripting....
I have a Script call Mail.ksh which calls Crank.ksh which calls Readdates.ksh whoch calls mindiff.ksh

the output of mindiff.ksh and Readdates.ksh are wirtten to a text file...
Here is how each file is called or executed...

./Mail.ksh 30 5 ( where count=30 and wait =5)
Crank.ksh `basename ${0}` $1 $2 > ${CUR_MAINT_DATE}.out
(Where Script name=`basename ${0}` Count= $1 wait= $2 )
Readdates.ksh Load_CAG${CUR_MAINT_DATE}
(Where Load_CAG is a log file it looking up in the log dir)

Code:
 
Readdates.ksh 
 
 
# Get the Julian equivalent of the current date, subtract 1 day, convert back to a date
typeset -i LSD_DAY LSD_MONTH LSD_YEAR LSD_JUL CMD_JUL CUR_MAINT_DATE
YYYYMMDD=`date +%Y%m%d`
LSD_DAY=$(echo ${YYYYMMDD} | awk '{print substr($1,7,2)}')
LSD_MONTH=$(echo ${YYYYMMDD} | awk '{print substr($1,5,2)}')
LSD_YEAR=$(echo ${YYYYMMDD} | awk '{print substr($1,1,4)}')
LSD_JUL=$(date2julian ${LSD_DAY} ${LSD_MONTH} ${LSD_YEAR})
(( CMD_JUL = LSD_JUL - 1 ))
CUR_MAINT_DATE=$(julian2date ${CMD_JUL})
#echo "Current maintenance date is ${CUR_MAINT_DATE}"
if [ "${1}" = "" ]
then
 filnam="Load_CLM_Claim_Table"
else
 filnam="${1}"
fi
if [ ! "${2}" = "" ]
then
 CUR_MAINT_DATE="${2}"
fi
#if [ -f /devl/acbu/logs/${CUR_MAINT_DATE}/${filnam}_200*log ]
if [ -f ${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log ]
then
#  ls /devl/acbu/logs/${CUR_MAINT_DATE}/${filnam}_200*log
  ls ${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log
  grep 'STEP 00' ${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log > r.tmp
  date1=`tail -1 r.tmp | cut -f2 -d '[' | cut -f1 -d ']'`
  grep 'Completed at \[' ${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log > r.tmp
  date2=`tail -1 r.tmp | cut -f2 -d '[' | cut -f1 -d ']'`
  rm -f r.tmp
  Mindiff.ksh ${date1} ${date2}
  if [ "${3}" != "" ]
  then
    grep "${3}" ${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log | head -1
  fi
else
  echo "${LOG_DIR}/${CUR_MAINT_DATE}/${filnam}_200*log not found!\n"
fi

Mindiff.ksh
Code:
if [[ "${1}" = "" ]] || [[ "${2}" = "" ]]
then
  echo "Missing one or both time parameter(s).  Calc: time2 - time1"
  exit
fi
time1=${1}
timelen=$(echo ${time1} | awk '{print length($1)}')
if [[ ${timelen} = 4 ]] then
 time1="0${time1}:00"
elif [[ ${timelen} = 5 ]] then
 time1="${time1}:00"
elif [[ ${timelen} = 7 ]] then
 time1="0${time1}"
fi
time2=${2}
timelen=$(echo ${time2} | awk '{print length($1)}')
if [[ ${timelen} = 4 ]] then
 time2="0${time2}:00"
elif [[ ${timelen} = 5 ]] then
 time2="${time2}:00"
elif [[ ${timelen} = 7 ]] then
 time2="0${time2}"
fi
typeset -i hour1 min1 sec1 hour2 min2 sec2 elapsed
hour1=$(echo ${time1} | awk '{print substr($1,1,2)}')
min1=$(echo ${time1} | awk '{print substr($1,4,2)}')
sec1=$(echo ${time1} | awk '{print substr($1,7,2)}')
(( sec1 = hour1 * 60 * 60 + min1 * 60 + sec1 ))
hour2=$(echo ${time2} | awk '{print substr($1,1,2)}')
min2=$(echo ${time2} | awk '{print substr($1,4,2)}')
sec2=$(echo ${time2} | awk '{print substr($1,7,2)}')
(( sec2 = hour2 * 60 * 60 + min2 * 60 + sec2 ))
if [[ sec2 -lt sec1 ]]
then
  (( sec2 = sec2 + 24*60*60 ))
fi
(( elapsed = sec2 - sec1 ))
typeset -i hour3 min3 sec3 elapsed3
elapsed3=elapsed
(( hour3 = elapsed3 / 3600 ))
(( elapsed3 = elapsed3 - hour3 * 3600 ))
(( min3 = elapsed3 / 60 ))
(( sec3 = elapsed3 - min3 * 60 ))
hour4="${hour3}"
timelen=$(echo ${hour4} | awk '{print length($1)}')
if [[ ${timelen} = 1 ]] then
 hour4="0${hour4}"
fi
min4="${min3}"
timelen=$(echo ${min4} | awk '{print length($1)}')
if [[ ${timelen} = 1 ]] then
 min4="0${min4}"
fi
sec4="${sec3}"
timelen=$(echo ${sec4} | awk '{print length($1)}')
if [[ ${timelen} = 1 ]] then
 sec4="0${sec4}"
fi
#echo "${1}-${2} = ${time1}-${time2} = ${sec2}-${sec1} or ${elapsed} sec = ${hour4}:${min4}:${sec4}"
#echo "${1} to ${2} = ${hour4}:${min4}:${sec4}"
echo "                         ${hour4}:${min4}:${sec4} = ${1} to ${2}"

this whole code runs fine... Now i need another text file which have only a part of Mindiff.ksh ie the last echo (only part of it) ${hour4}:${min4}:${sec4}

i need list of this echo in a text file called runtime.out is there any possibel way to do it...

If you need more info please let me know... any suggestions are welcomed

Thanks a lot
# 2  
Old 01-20-2009
I'm guessing you did not write that code.
code]
# change this
echo " ${hour4}:${min4}:${sec4} = ${1} to ${2}"
# to this
echo " ${hour4}:${min4}:${sec4} = ${1} to ${2}" >> runtime.out
[/code]
You will also have to add
Code:
> runtime.out

up near the top of the Mail.ksh file
[/code]
# 3  
Old 01-20-2009
Yes i havnt written the code... Unix is not my area of field...
anways where excatly you want to to add > runtime.out
do you mean at ./Mail.ksh 30 5 > runtime.out
please correct me if i am wrong

Thanks
# 4  
Old 01-20-2009
Actually you got my question wrong... I want the script to write to current_date.out as it is writing now... i want to add another file called runtime .out where it should only echo part of the echo statement
ie echo "${hour4}:${min4}:${sec4}"

I want this echo on a seperate file...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh

Hi Dears kindly I am new here ...I want to ask your help ... I want to write AWK command when enter date like 20140129 plus 9 then it gives me 20140207 I wrote below but the result was wrong #!/bin/ksh echo "please input the data:" read a if echo $a|awk '{if... (15 Replies)
Discussion started by: shaho87
15 Replies

2. Shell Programming and Scripting

Need help with ksh

I have the following file: one two three four man women yes no place togo bad sleep I need to move all lines that have only two words(columns) in a separate file and the rest in a separate file... I used : for $linecont in $(cat $filename); do echo $linecont > temp line1='cat... (7 Replies)
Discussion started by: daimne
7 Replies

3. Shell Programming and Scripting

ksh help

Hi, I have command like this with ooutput : unix>tnsping abc TNS Ping Utility for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 17-AUG-2011 17:06:11 Copyright (c) 1997, 2007, Oracle. All rights reserved. Used parameter files: /opt/oracle/network/admin/sqlnet.ora ... (19 Replies)
Discussion started by: talashil
19 Replies

4. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

5. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

Need help on ksh

1. Script using bash #!/bin/bash a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 2147483648 2. Script using ksh #!/bin/ksh a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 (3 Replies)
Discussion started by: gautam.shrestha
3 Replies

8. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

9. Shell Programming and Scripting

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

10. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies
Login or Register to Ask a Question