?
Solved

Cannot capture date-time in a Unix ksh script

Posted on 2009-04-29
10
Medium Priority
?
746 Views
Last Modified: 2013-12-26
I am trying to capture the date/time in a Unix script to then insert as a date field into an Oracle table.

This has worked for me: dateparm=`date "+%d-%b-%Y-%T"`
- I use this to append dateparm to a logfile name

But this is not working for me: time_end =`date "+%x %X"`
- This comes up blank in the record inserted in Oracle and when I echo it in the log file, in the log file it looks like this: time_end =


# get the start time per source but only for the first time
      if [ ${TBLNAME} = "PRODT_NM" ]
      then
          time_start=`date "+%x %X"`
      fi
 
. . . 
#get time end per source
      time_end =`date "+%x %X"`
 
      echo "time_end = ${time_end}" >> /tmp/prd_srcelog$$
 
. . . . 
insert into ods.proc_slog values ('172','$time_end', sysdate+5, sysdate+6,0,'OKAY','200904',sysdate+7,'bpeck','test')

Open in new window

0
Comment
Question by:Alaska Cowboy
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 300 total points
ID: 24262595
try it without the space between  time_end and =
0
 
LVL 5

Expert Comment

by:louislietaer
ID: 24262883
Yes ozo has the right answer, just test it
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 24263078
oh, thanks, I guess I had stared at it too long.

worked for time_end (removing the extraneous space)

it's not working for time_start, is there something wrong with the if stmt ? re-posted snippet here


# get the start time per source but only for the first time
      if [ ${TBLNAME} = "PRODT_NM" ]
      then
          time_start=`date "+%x %X"`
      fi

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 24263133
sorry, time_start working too.

thanks for the 2nd set of eyes
0
 
LVL 85

Expert Comment

by:ozo
ID: 24263161
what is $TBLNAME?
0
 
LVL 5

Assisted Solution

by:louislietaer
louislietaer earned 100 total points
ID: 24263164
Are you sure if [ ${TBLNAME} = "PRODT_NM" ] is true ?
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 24263756
ozo - TBLNAME is a table that is being sql*loaded to Oracle - I needed to upper case it . . .

louis - yes, good point, I had to upper-case it, now it works, yea.
0
 
LVL 62

Assisted Solution

by:gheist
gheist earned 100 total points
ID: 24265066
try now() in oracle...
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 24265257
gheist, thanks, I never used that, so good to know. but I am capturing the time of events throughout the script and so need to capture it.
0
 
LVL 62

Expert Comment

by:gheist
ID: 24265525
You can use logger for system to record timed events. No need to go leaps around via database. Then use syslog-ng atop database to insert data into DB.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Utilizing an array to gracefully append to a list of EmailAddresses
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question