Sponsored Content
Full Discussion: Time Diff in shell script
Top Forums Shell Programming and Scripting Time Diff in shell script Post 302448323 by posner on Wednesday 25th of August 2010 07:37:01 PM
Old 08-25-2010
Time Diff in shell script

Hi all ,

i am trying to calculate time difference btw the script execution

I am using solaris

Code:
start_time=`date +%s` 
sleep 2
end_time=`date +%s`
duration=`expr $end_time - $start_time`
when   i try to subtract i get the error 
 line 13: %s - -time : syntax error: operand expected (error token is "%s - -time ")

i think start_time=`date +%s` doesn't work in solaris because this is working in other linux box

later on i calculate the time to minutes
Code:
minutes=$(echo "scale=2; $duration / 60" | bc)

which gives some error in seconds but thats ok
and i cant calculate again to hours which gives errors in minutes

so all i am trying to achieve is
Code:
#!bin/bash

start_time=??

--script logic

end_time=??
 
durtation=??

echo "$duration"

this on a solaris system

thanks in advance

Last edited by Scott; 08-25-2010 at 08:40 PM.. Reason: Use code tags next time. Thanks in advance :)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to manipulate a message count for the same IP @ diff session

I have a file as like below, 10:20:30.45 START 10.20.30.40 10:20:31.46 HELLO 10.20.30.40 10:20:32.46 START 10.20.30.41 10:20:33.44 END 10.20.30.40 10:20:35.44 HELLO 10.20.30.41 10:20:36.56 HELLO 10.20.30.41 10:20:37.78 HELLO 10.20.30.41 10:20:38.99 START 10.20.30.40... (1 Reply)
Discussion started by: gobinath
1 Replies

2. Shell Programming and Scripting

Process diff command output in a shell script

diff -yta file1 file2 #!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8 Notable thing about above line is "|" appears at 62nd position. When the same line is assigned in a variable in a ksh script, using ss=$(diff -yta file1 file2) it appears as ... (4 Replies)
Discussion started by: bhaliyajalpesh
4 Replies

3. Shell Programming and Scripting

Shell script using Diff

Hello - I have a small diff script that checks 2 directories. It reports the difference in count such as wc -l, and also names the different files. How should I get "ERROR: diff found . (host)" - when it actually finds a diff? This is how I have written: #!/bin/bash ... (10 Replies)
Discussion started by: DallasT
10 Replies

4. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

5. UNIX for Dummies Questions & Answers

Diff between calling a shell script with ./ and . ./

Hi ALL I have a shell script named setUP in which i am sourcing one variable like source var_name="CLASSPATH". When i call it as ./setUP, it does not set the var_name variable. But when i call it like . ./setUP then var_name is set up. What is the difference between this two calls? ... (1 Reply)
Discussion started by: SasDutta
1 Replies

6. Shell Programming and Scripting

Diff between calling a shell script with ./ and . ./

Hi ALL I have a shell script named setUP in which i am sourcing one variable like source var_name="CLASSPATH". When i call it as ./setUP, it does not set the var_name variable. But when i call it like . ./setUP then var_name is set up. What is the difference between this two calls? ... (2 Replies)
Discussion started by: SasDutta
2 Replies

7. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

8. Shell Programming and Scripting

Shell script to compare ,diff and remove betwen 2 files

Hi Friends Need your expertise. Command to check the difference and compare 2 files and remove lines . example File1 is master copy and File2 is a slave copy . whenever i change, add or delete a record in File1 it should update the same in slave copy . Can you guide me how can i accomplish... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

9. Shell Programming and Scripting

Howto compare the columns of 2 diff tables of 2 different schemas in UNIX shell script

HI All, I am new to Unix shell scripts.. Could you please post the unix shell script for for the below request., There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2). Unix shell script to compare the columns of two different tables of two... (2 Replies)
Discussion started by: Rajkumar Gopal
2 Replies

10. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies
Duration(3pm)						User Contributed Perl Documentation					     Duration(3pm)

NAME
Time::Duration - rounded or exact English expression of durations SYNOPSIS
Example use in a program that ends by noting its runtime: my $start_time = time(); use Time::Duration; # then things that take all that time, and then ends: print "Runtime ", duration(time() - $start_time), ". "; Example use in a program that reports age of a file: use Time::Duration; my $file = 'that_file'; my $age = $^T - (stat($file))[9]; # 9 = modtime print "$file was modified ", ago($age); DESCRIPTION
This module provides functions for expressing durations in rounded or exact terms. In the first example in the Synopsis, using duration($interval_seconds): If the "time() - $start_time" is 3 seconds, this prints "Runtime: 3 seconds.". If it's 0 seconds, it's "Runtime: 0 seconds.". If it's 1 second, it's "Runtime: 1 second.". If it's 125 seconds, you get "Runtime: 2 minutes and 5 seconds.". If it's 3820 seconds (which is exactly 1h, 3m, 40s), you get it rounded to fit within two expressed units: "Runtime: 1 hour and 4 minutes.". Using duration_exact instead would return "Runtime: 1 hour, 3 minutes, and 40 seconds". In the second example in the Synopsis, using ago($interval_seconds): If the $age is 3 seconds, this prints "file was modified 3 seconds ago". If it's 0 seconds, it's "file was modified just now", as a special case. If it's 1 second, it's "from 1 second ago". If it's 125 seconds, you get "file was modified 2 minutes and 5 seconds ago". If it's 3820 seconds (which is exactly 1h, 3m, 40s), you get it rounded to fit within two expressed units: "file was modified 1 hour and 4 minutes ago". Using ago_exact instead would return "file was modified 1 hour, 3 minutes, and 40 seconds ago". And if the file's modtime is, surprisingly, three seconds into the future, $age is -3, and you'll get the equally and appropriately surprising "file was modified 3 seconds from now." FUNCTIONS
This module provides all the following functions, which are all exported by default when you call "use Time::Duration;". duration($seconds) duration($seconds, $precision) Returns English text expressing the approximate time duration of abs($seconds), with at most "$precision || 2" expressed units. (That is, duration($seconds) is the same as duration($seconds,2).) For example, duration(120) or duration(-120) is "2 minutes". And duration(0) is "0 seconds". The precision figure means that no more than that many units will be used in expressing the time duration. For example, 31,629,659 seconds is a duration of exactly 1 year, 1 day, 2 hours, and 59 seconds (assuming 1 year = exactly 365 days, as we do assume in this module). However, if you wanted an approximation of this to at most two expressed (i.e., nonzero) units, it would round it and truncate it to "1 year and 1 day". Max of 3 expressed units would get you "1 year, 1 day, and 2 hours". Max of 4 expressed units would get you "1 year, 1 day, 2 hours, and 59 seconds", which happens to be exactly true. Max of 5 (or more) expressed units would get you the same, since there are only four nonzero units possible in for that duration. duration_exact($seconds) Same as duration($seconds), except that the returned value is an exact (unrounded) expression of $seconds. For example, duration_exact(31629659) returns "1 year, 1 day, 2 hours, and 59 seconds later", which is exactly true. ago($seconds) ago($seconds, $precision) For a positive value of seconds, this prints the same as "duration($seconds, [$precision]) . ' ago'". For example, ago(120) is "2 minutes ago". For a negative value of seconds, this prints the same as "duration($seconds, [$precision]) . ' from now'". For example, ago(-120) is "2 minutes from now". As a special case, ago(0) returns "right now". ago_exact($seconds) Same as ago($seconds), except that the returned value is an exact (unrounded) expression of $seconds. from_now($seconds) from_now($seconds, $precision) from_now_exact($seconds) The same as ago(-$seconds), ago(-$seconds, $precision), ago_exact(-$seconds). For example, from_now(120) is "2 minutes from now". later($seconds) later($seconds, $precision) For a positive value of seconds, this prints the same as "duration($seconds, [$precision]) . ' later'". For example, ago(120) is "2 minutes later". For a negative value of seconds, this prints the same as "duration($seconds, [$precision]) . ' earlier'". For example, later(-120) is "2 minutes earlier". As a special case, later(0) returns "right then". later_exact($seconds) Same as later($seconds), except that the returned value is an exact (unrounded) expression of $seconds. earlier($seconds) earlier($seconds, $precision) earlier_exact($seconds) The same as later(-$seconds), later(-$seconds, $precision), later_exact(-$seconds). For example, earlier(120) is "2 minutes earlier". concise( function( ... ) ) Concise takes the string output of one of the above functions and makes it more concise. For example, "ago(4567)" returns "1 hour and 16 minutes ago", but "concise(ago(4567))" returns "1h16m ago". I18N/L10N NOTES Little of the internals of this module are English-specific. See source and/or contact me if you're interested in making a localized version for some other language than English. BACKSTORY
I wrote the basic "ago()" function for use in Infobot ("http://www.infobot.org"), because I was tired of this sort of response from the Purl Infobot: me> Purl, seen Woozle? <Purl> Woozle was last seen on #perl 20 days, 7 hours, 32 minutes and 40 seconds ago, saying: Wuzzle! I figured if it was 20 days ago, I don't care about the seconds. So once I had written "ago()", I abstracted the code a bit and got all the other functions. CAVEAT
This module calls a durational "year" an interval of exactly 365 days of exactly 24 hours each, with no provision for leap years or monkey business with 23/25 hour days (much less leap seconds!). But since the main work of this module is approximation, that shouldn't be a great problem for most purposes. SEE ALSO
Date::Interval, which is similarly named, but does something rather different. Star Trek: The Next Generation (1987-1994), where the character Data would express time durations like "1 year, 20 days, 22 hours, 59 minutes, and 35 seconds" instead of rounding to "1 year and 21 days". This is because no-one ever told him to use Time::Duration. COPYRIGHT AND DISCLAIMER
Copyright 2006, Sean M. Burke "sburke@cpan.org", all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. AUTHOR
Current maintainer Avi Finkel, "avi@finkel.org"; Original author Sean M. Burke, "sburke@cpan.org" perl v5.10.1 2007-08-19 Duration(3pm)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy