capturing the time stamp to get hours


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers capturing the time stamp to get hours
# 1  
Old 07-24-2006
capturing the time stamp to get hours

Hi All,

I am working on a korn shell script.

I have a problem.i am calculating the next 27 hours
from the time stamp.

say TSTAMP=20060724000000

if i add 27 hours to the above time stamp,
i will get 20060724143000

this is the code:

YEAR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,1,4));}'`
MONTH=`echo $TSTAMP | awk '{printf("%s\n",substr($0,5,2));}'`
DAY=`echo $TSTAMP | awk '{printf("%s\n",substr($0,7,2));}'`
HOUR=`echo $TSTAMP | awk '{printf("%s\n",substr($0,9,2));}'`
MIN=`echo $TSTAMP | awk '{printf("%s\n",substr($0,11,2));}'`
SEC=`echo $TSTAMP | awk '{printf("%s\n",substr($0,13,2));}'`


echo "$YEAR $MONTH $DAY $HOUR $MIN $SEC" |
awk '{ printf("%s\n",strftime("%Y%m%d%H%M%S",mktime($0)+27*3600)); }'


the code is working fine. but now the 27 hours is coming as a parameter. say num.
so num can be num=27 or num=2.5 or num=0.75 or any value. it is coming from upstream process.

if I pass num as paramter in the above code as follows then it is not working..I am getting non numeric error.

echo "$YEAR $MONTH $DAY $HOUR $MIN $SEC" |
awk '{ printf("%s\n",strftime("%Y%m%d%H%M%S",mktime($0)+$num*3600)); }'

can anyone please advice me.

Thanks & regards
pavi
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capturing time stamp in file name

I have a file that is created via a perl script where the file is named like so: 01-07-2016_10:17:08. I am running a shell script that needs to take this file and print it. I can capture the date portion fine, but I am unsure how to capture the time stamp, since there will be a difference from what... (1 Reply)
Discussion started by: ldorsey
1 Replies

2. UNIX for Advanced & Expert Users

Need mtime with time stamp

hi all find /folder1 -mtime 1 >folder1 with the above command , I can get the output of all the files which are modified(within folders and sub folders of folder1) in the last 24 hours. but the listed files output , does not contain the time stamp with it. I request you to give... (4 Replies)
Discussion started by: sidharthmellam
4 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

file time stamp

Hi All, I am facing small problem. i want to print file time stamp on which date file has placed in the server. i have given some code but its not giving the year. any help appreciated. regards rajesh. (4 Replies)
Discussion started by: rajesh_pola
4 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. Shell Programming and Scripting

Time stamp calculation

Hi all; I'm relatively new to scripting,I am working on a monitoring script.....where in i have to write subroutine which does the follows: It will check the time stamp of a file ( Oracle remarchive files) and compare it with existing time.If the time difference happen to be more than 90... (6 Replies)
Discussion started by: maverick_here
6 Replies

8. UNIX for Dummies Questions & Answers

capturing the time stamp in desired format

Hello All, I am working on korn shell script.i have 2 questions; 1) I have a file and i am able to capture the arrival time. the arrival time is capturing as 11:30 ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}' 11:30 my desired output is 113000 can anyone please suggest me... (2 Replies)
Discussion started by: pavan_test
2 Replies

9. UNIX for Dummies Questions & Answers

capturing the time stamp

Hi All, I am working on a korn shell script. i have a file such as: DS.PETSCO.20060601203514.20060531.ctl_20060717124431 i have 2 problems here. 1) i have to capture the time stamp from the above file i.e this number 20060717124431. format of time stamp is YYYYMMDDHHMMSS. can... (4 Replies)
Discussion started by: pavan_test
4 Replies

10. UNIX for Dummies Questions & Answers

How to MV without changing Time Stamp

Hi, I need to move the set of files, and it should be same time stamp as previous. How to do this? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question
PCAP-TSTAMP(7)						 Miscellaneous Information Manual					    PCAP-TSTAMP(7)

NAME
pcap-tstamp - packet time stamps in libpcap DESCRIPTION
When capturing traffic, each packet is given a time stamp representing, for incoming packets, the arrival time of the packet and, for out- going packets, the transmission time of the packet. This time is an approximation of the arrival or transmission time. If it is supplied by the operating system running on the host on which the capture is being done, there are several reasons why it might not precisely repre- sent the arrival or transmission time: if the time stamp is applied to the packet when the networking stack receives the packet, the networking stack might not see the packet until an interrupt is delivered for the packet or a timer event causes the networking device driver to poll for packets, and the time stamp might not be applied until the packet has had some processing done by other code in the networking stack, so there might be a significant delay between the time when the last bit of the packet is received by the capture device and when the net- working stack time-stamps the packet; the timer used to generate the time stamps might have low resolution, for example, it might be a timer updated once per host operat- ing system timer tick, with the host operating system timer ticking once every few milliseconds; a high-resolution timer might use a counter that runs at a rate dependent on the processor clock speed, and that clock speed might be adjusted upwards or downwards over time and the timer might not be able to compensate for all those adjustments; the host operating system's clock might be adjusted over time to match a time standard to which the host is being synchronized, which might be done by temporarily slowing down or speeding up the clock or by making a single adjustment; different CPU cores on a multi-core or multi-processor system might be running at different speeds, or might not have time counters all synchronized, so packets time-stamped by different cores might not have consistent time stamps. In addition, packets time-stamped by different cores might be time-stamped in one order and added to the queue of packets for libpcap to read in another order, so time stamps might not be monotonically increasing. Some capture devices on some platforms can provide time stamps for packets; those time stamps are usually high-resolution time stamps, and are usually applied to the packet when the first or last bit of the packet arrives, and are thus more accurate than time stamps provided by the host operating system. Those time stamps might not, however, be synchronized with the host operating system's clock, so that, for example, the time stamp of a packet might not correspond to the time stamp of an event on the host triggered by the arrival of that packet. Depending on the capture device and the software on the host, libpcap might allow different types of time stamp to be used. The pcap_list_tstamp_types(3PCAP) routine provides, for a packet capture handle created by pcap_create(3PCAP) but not yet activated by pcap_activate(3PCAP), a list of time stamp types supported by the capture device for that handle. The list might be empty, in which case no choice of time stamp type is offered for that capture device. If the list is not empty, the pcap_set_tstamp_type(3PCAP) routine can be used after a pcap_create() call and before a pcap_activate() call to specify the type of time stamp to be used on the device. The time stamp types are listed here; the first value is the #define to use in code, the second value is the value returned by pcap_tstamp_type_val_to_name() and accepted by pcap_tstamp_name_to_val(). PCAP_TSTAMP_HOST - host Time stamp provided by the host on which the capture is being done. The precision of this time stamp is unspecified; it might or might not be synchronized with the host operating system's clock. PCAP_TSTAMP_HOST_LOWPREC - host_lowprec Time stamp provided by the host on which the capture is being done. This is a low-precision time stamp, synchronized with the host operating system's clock. PCAP_TSTAMP_HOST_HIPREC - host_hiprec Time stamp provided by the host on which the capture is being done. This is a high-precision time stamp; it might or might not be synchronized with the host operating system's clock. It might be more expensive to fetch than PCAP_TSTAMP_HOST_LOWPREC. PCAP_TSTAMP_ADAPTER - adapter Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp, synchronized with the host operating system's clock. PCAP_TSTAMP_ADAPTER_UNSYNCED - adapter_unsynced Time stamp provided by the network adapter on which the capture is being done. This is a high-precision time stamp; it is not synchronized with the host operating system's clock. SEE ALSO
pcap_set_tstamp_type(3PCAP), pcap_list_tstamp_types(3PCAP), pcap_tstamp_type_val_to_name(3PCAP), pcap_tstamp_name_to_val(3PCAP) 22 August 2010 PCAP-TSTAMP(7)