timer

Hi all,

Wanted to a create a shell script
-----------------------------------------------------------------------
1) which when called will start a timer and wait for 48 hours.
after 48 hours it will call some function(say XYZ)

2) Whenever this shell script is called (can be called anytime), the timer again starts from 1.
-----------------------------------------------------------------------

can this be possible..

script

-----------------START------------------------------------------

dt_start_var1 = get date and time.(that will be almost
when this script is called)

dt_target_var2 = dt_var1 + 48 hrs

do while loop

 \# keep on getting the lastest date and time
  current\_dt_var =  get current date and time. 

  \# then compare
  if current\_dt_var  >= dt\_target_var2   then break;

end

call ( XYZ function)

---------------------------END--------------------------------

if above steps are possible in Shell SCript can please anybody provide with the syntax and code for the above 7 lines.
Or else any alternate solution.

Will be greatly thankful.

Thanks in advance.

k_oops

If I understand the question, your approach is not the best. There is no need to loop. Two lines will do it:

sleep 172800
XYZ

Except that if the box reboots in the next 48 hours, this will be lost. Maybe that is what you want. If not, create a shell script to run in 48 hours and use:
at -f /path/to/run_XYZ now + 48 hours

See "man at" for more info.

Thanks perderabo,

2 lines of code works. Thanks again.

One more thing, if server is rebooted, then
any idea how I will be able to restore the
seconds.

If suppose the script is invoked on Monday 3.00 pm, then
function XYZ should be called on Wednesday 3.00 pm( assuming
that the script is not invoked in between. ) even if there are 1 or more server reboots in between.

k_oops

To persist across reboots use the "at" command as I mentioned.