How to add and extra hour to the start time

Hi

Actually what am trying to ask is , i have an shell script ,now i want to run this shell script for one hour continuously and after one hour it has to stop automatically.
can any one suggest me how to automate the shell script ?
we tried wth the getting the start time and add ing an hour to that , but we faield in that ?

please any one help me in resolving this issue

thanks in advance
lalitha

This is weird, why should you stop a script after one hour?
Clarify what you're trying to achieve with your script, show what have you tried so far and where you are stuck.

Regards

Actually i am doing some regression testing ...................

where we need to test one driver continuously for one hour ........... and need to check whether the driver test is performing fine or not , and here is the script
otalcount=0
failcount=0
passcount=0
testcase=0
failing_test=0
PresentTime=$(date +%k%M)
let TargetTime=$PresentTime+100
echo "TargetTime is $TargetTime"
touch /home/mohanav/DeviceDrivers/Logs/CLK_one_hour.txt
cd /opt/qcom/bin/tests
echo "============================================================================================================================="
let totalcount=totalcount+1;
iteration=0
while [ $iteration -lt 780 ]
do
let iteration_count=iteration+1
./clk_test.sh -v >> /home/mohanav/DeviceDrivers/Logs/CLK_one_hour.txt
if [ $? -ne 0 ]
then
echo $?
echo "script: TEST FAILED"
testcase="clk_test"
echo "testcase is = $testcase"
echo "the test cases failing in $iteration_count iteration is $testcase driver" >> /home/mohanav/DeviceDrivers/Repeatability/repeatability_clk_test.txt
let failcount=failcount+1;
fi
let iteration=iteration+1
done
echo "================

so we need to run this for one hour continuously ...........?

The following is written to run for ten seconds; adjust the 10 to the appropriate number of seconds. (I did for ten for easier testing and to see that it works.)

> cat run_time
#! /usr/bin/bash

#variables
initial_time="test_file_start"
current_time="test_file_current"
time_diff_goal=10  # the number of seconds before exit

touch $initial_time
time1=`stat -c %Y $initial_time`

while [ 1 -eq 1 ]
   do

# do some stuff here

      touch $current_time
      time2=`stat -c %Y $current_time`

      time_diff=`echo $time2 - $time1 | bc`
      if [ $time_diff -ge $time_diff_goal ]
         then
         echo $time_diff
         exit 99
      fi
done

Hi

thanks for your response, i am trying to execute your script but while executing the belwo command

time1=`stat -c %Y $initial_time` in the linux console

i am getting an error as " stat not found"

????

and by the way I need the answer using shell script

I approached from a general unix perspective.
A quick google search seemed to show that stat was available in linux.
Linux Command Directory: stat

yes its avialbel but dont know when i am trying to run the same command its showing as stat not found , and we are using red hat linux .........(as a general info)

so can u suggest me any other way to solve this ? probelm

You can solve this problem without intermediate files and without using the stat utility by simple calculation. I will sketch out a solution which will not cover for situations where the intervall is going over midnight, but even this could easily built in:

  1. Find out the number of seconds passed since midnight. This is easily done using the "date" command and applying the appropriate format. I have no Linux system available, so you will have to look up the man page yourself, but the following details can surely be specified: Number of hours since midnight, number of minutes in the current hour, number of seconds in the current minute. Add that all: hours * 3600 + minutes * 60 + seconds.

Example: 10:15:03 103600 + 1560 + 3 = 36000 + 900 + 3 = 36903

  1. Add to that 3600 (1 hour in seconds) to get the time of termination.

  2. Get the number of passed seconds since midnight the same way as in 1. Compare this to your termination number and if its greater than that the hour has passed.

I hope this helps.

bakunin