store timestamp in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting store timestamp in a variable
# 1  
Old 10-04-2008
Question store timestamp in a variable

I am new to Unix shell Script
_________________________
db2 connect to r2pdev user bmwdevup using summer08 >>$monlog
# get the current timestamp from SYSIBM.SYSDUMMY1
currenttimestamp=""
echo "Run SQL select current timestamp from SYSIBM.SYSDUMMY1 with ur" >>$monlog
db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" >> currenttimestamp
cat currenttimestamp
_________________________
Following is the output
_________________________

1
-----------------------------
2008-10-04-07.49.11.214113
1 record(s) selected

_________________________
I need only the timestamp i.e, 2008-10-04-07.49.11.214113. This timestamp should be stored in a variable and I need to pass this timestamp variable to another query.

can any one help us to fix this problem.

thanks in advance.

Krishnakanth
# 2  
Old 10-04-2008
Code:
currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" | awk '/selected$/{print s;exit}{s=$0}'`

Regards
# 3  
Old 10-04-2008

Code:
currenttimestamp=$( db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" |
grep '^[12][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' )

# 4  
Old 10-06-2008
Thanks for your reply.

The code is not working. I simply copied and pasted it. I don't know why ?.

Could you please explain the function of "grep '^[12][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]"

Krishnakanth
# 5  
Old 10-06-2008
F Y I.. we are using Korn Shell .ksh ..

Krishnakanth
# 6  
Old 10-06-2008
^ matches beginning of line

[12] matches a 1 or a 2

[0-9] matches a digit between 0 and 9

- simply matches a literal dash

Maybe your output has spaces before the date? Try ^ *[12][0-9] etc (add a space and an asterisk after the ^)
# 7  
Old 10-06-2008
I am giving the output as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# cat currenttimestamp

1
--------------------------
2008-10-06-10.06.01.455592

1 record(s) selected.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I need only the timestamp
2008-10-06-10.06.01.455592

and I don't want all other info.

Can any one help us to fix this problem.

Krishnakanth
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

2. Shell Programming and Scripting

How to store file name in a variable?

Hi All, Daily I am generating a file dfm_daily_file_ ex: dfm_daily_file_05072015 date will be changed daily. Once the file is FTP it is deleted. I have tried the below code to get the file name with any date and store it in a variable its not working. #!/bin/ksh ... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies

3. Shell Programming and Scripting

Store ^M character in variable

Hi, I want to store ^M character in a variable to be later written to a file. Can you please help. TempOut="$_var1 `print '\x0D'` $_var1" ..... .... echo $TempOut >> logfile TempOut="$_var1 `echo -e '\x0D'` $_var1" ..... .... echo $TempOut >> logfile But both ways I am... (2 Replies)
Discussion started by: tostay2003
2 Replies

4. Shell Programming and Scripting

I can't store value in the variable

!#bin/bash clear var= grep @gmail.com email.txt | wc -l echo $var echo $var exit 0 OUTPUT: 1000 _ _ Where _ represent space (no value or nothing) (4 Replies)
Discussion started by: Muhammad Rehan
4 Replies

5. UNIX Desktop Questions & Answers

How to store the value of grep in a variable

Hi , I was trying to store the value of a grep command to store in a variable so i can use it somewhere else in my script but i am getting error, i am using bash shell in linux: var= `grep -n "$DATE" testfile.log | head -n 1 | sed -n 's/^\(*\).*/\1/p` echo "$var"I get the error: unexpected... (5 Replies)
Discussion started by: learninguser235
5 Replies

6. Shell Programming and Scripting

cut and store last value of a variable into other

Hi All, I am a newbie to unix.starting my career in unix.need 1 help from you all..pls help.. i am passing a file name "abc_delta" as argument to my script1.sh. if file name contains "_delta" at last then echo pass else fail.how to fix it. Note:file name will always contain "_delta" at... (10 Replies)
Discussion started by: pradeepcarya
10 Replies

7. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

8. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

9. Shell Programming and Scripting

Help in scripting, store value in variable

Hi all, I have a script in which i need to run a command like "/opt/dell/srvadmin/sbin/omreport about" and output will be something like Version : 6.3.0 Copyright : Copyright (C) xxx Inc. 1995-2010 All rights reserved. Company : xxx Inc. In this i need to save the version... (13 Replies)
Discussion started by: Renjesh
13 Replies

10. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies
Login or Register to Ask a Question