script execution time calculation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script execution time calculation
# 8  
Old 02-24-2006
Here is the original code I was trying to get to work:
#!/bin/ksh

BDAY=$(date +%e)
((BTIME=($(date +%H)*3600)+($(date +%M)*60)+$(date +%S)))

time sleep 20

EDAY=$(date +%e)
# assumes run time not over 48 hours.
[[ $BDAY == $EDAY ]] && DAY=0 || DAY=86400
((ETIME=$DAY+($(date +%H)*3600)+($(date +%M)*60)+$(date +%S)))

((TOTAL=$ETIME - $BTIME))
print "Run Time: \c"
((HOURS=TOTAL / 3600))
((TOTAL=TOTAL - (HOURS*3600)))
print "$HOURS hours, $((TOTAL / 60)) minutes, $((TOTAL % 60)) seconds."


The above code has given me a variety of error messages that I have fixed and the latest is:

real 0m20.02s
user 0m0.00s
sys 0m0.00s
./fun4[13]: syntax error at line 16 : `==' unexpected

Maybe you can see what is wrong - Thanks
# 9  
Old 02-24-2006
the 'time sleep 20' line doesn't make sense to use. it's only timing the sleep command which you know will execute for only 20 seconds. er... apparently 20.02 seconds. Smilie

maybe you can wrap a script around it which uses the 'time' command against the script you wanna run. just a thought. *shrugs*
# 10  
Old 02-25-2006
The time sleep 20 is used for nothing more than testing. the real script is preforming some software and database upgrades. The only reason why i used the time command is so it would actually display the 20 sec to the screen. just a habbit of mine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To take script execution time

Hello Guys, I would like to know is there a way to take the script execution time For e.g i am having a script.sh i need to write inside he script.sh like Start time : 10-Mar-2016 02:30:35 all code over here ... End time : 10-Mar-2016 03:30:32 Script start time - 02:30:35 ... (7 Replies)
Discussion started by: Master_Mind
7 Replies

2. Shell Programming and Scripting

Optimizing script to reduce execution time

AFILENAME=glow.sh FILENAME="/${AFILENAME}" WIDTHA=$(echo ${FILENAME} | wc -c) NTIME=0 RESULTS=$(for eachletter in $(echo ${FILENAME} | fold -w 1) do WIDTHTIMES=$(awk "BEGIN{printf... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

How to do simple date (time) calculation in shell script?

Hi, I'm looking for a way to do a simple math calc during a shell script as a means of logging how long a particular task takes. For example... STARTTIME=whenever this script starts ./path/to/command.sh >>logfile.log TOTALTIME=<time at this stage of the script after above command... (7 Replies)
Discussion started by: nbsparks
7 Replies

4. Shell Programming and Scripting

Find execution time of script

i am using bash START=$(date +%s) END=$(date +%s) DIFF=$(echo "$END - $START" ) this code is not working (14 Replies)
Discussion started by: rafa_fed2
14 Replies

5. Shell Programming and Scripting

time calculation in ksh script

I"m trying to calculate the duration of of backup within a ksh shell script but I get an error. #!/bin/ksh STTIM=`date '+%T'` EDTIM=`date '+%T'` .... .... echo "DURATION OF BACKUP: $((EDTIM - STTIM))" (5 Replies)
Discussion started by: Bperl1967
5 Replies

6. Shell Programming and Scripting

execution time / runtime -- bash script please help!

Hello, I'm running a bash script and I'd like to get more accurate a runtime information then now. So far I've been using this method: STARTM=`date -u "+%s"` ......... *script function.... ......... STOPM=`date -u "+%s"` RUNTIMEM=`expr $STOPM - $STARTM` if (($RUNTIMEM>59)); then... (6 Replies)
Discussion started by: TehOne
6 Replies

7. UNIX for Dummies Questions & Answers

script start and end of execution of time

Hi All, Can we get to know the start time and end time of execution of a script? (This script doesn't write any logs.) I mean, is there any built in process logs to track these records? (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

8. Shell Programming and Scripting

get execution time of a script

Hi, I have a simple question. How can I get the execution time of a script and maybe put it in a variable? Another question. How can I get only time and not date and put it in a variable? I tried something with "date" command but with no success... If someone could help me... (8 Replies)
Discussion started by: Moumou
8 Replies

9. Shell Programming and Scripting

time of execution of script

i want to test whether a script has been executed in last 15 days or not....please help how can i do this...is there any copmmand there to know timings of last execution of any script (8 Replies)
Discussion started by: arghya_owen
8 Replies

10. UNIX for Advanced & Expert Users

time calculation

Hi, I have start time as a string like 06:04:01 and end time like 06:05:01 i need do a simple math to get the duration. What is the best way to do this in Korn Shell scripting? Thanks (2 Replies)
Discussion started by: liux99
2 Replies
Login or Register to Ask a Question