Automatically run a script every n seconds

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatically run a script every n seconds

babelproofreader
Is there a way to make Octave automatically run a particular script every n
seconds, where n is user specified? The intent is to check a (financial)
website every n seconds for a change in the data hosted on the website and
then take some conditional action. I suppose I could write a while loop, but
I was wondering if there is a dedicated Octave function/method for this.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Automatically run a script every n seconds

Andreas Weber-6
Am 04.04.20 um 18:03 schrieb babelproofreader:
> Is there a way to make Octave automatically run a particular script every n
> seconds, where n is user specified?

The other software product has a "timer" object which does what you want:
mathworks.com/help/matlab/matlab_prog/use-a-matlab-timer-object.html

But it looks it isn't implemented yet in GNU Octave.
-- Andy


Reply | Threaded
Open this post in threaded view
|

Re: Automatically run a script every n seconds

Dr.-Ing. Dieter Jurzitza
In reply to this post by babelproofreader
Hello babelproofreader,
in Linux you could put this in a crontab entry.
Take care

Dieter
Am Samstag, 4. April 2020, 18:03:43 CEST schrieb babelproofreader:

> Is there a way to make Octave automatically run a particular script every n
> seconds, where n is user specified? The intent is to check a (financial)
> website every n seconds for a change in the data hosted on the website and
> then take some conditional action. I suppose I could write a while loop, but
> I was wondering if there is a dedicated Octave function/method for this.
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


--
-----------------------------------------------------------
Dr.-Ing. Dieter Jurzitza                    76131 Karlsruhe





Reply | Threaded
Open this post in threaded view
|

Re: Automatically run a script every n seconds

babelproofreader
Dr.-Ing. Dieter Jurzitza wrote

> Hello babelproofreader,
> in Linux you could put this in a crontab entry.
> Take care
>
> Dieter
> Am Samstag, 4. April 2020, 18:03:43 CEST schrieb babelproofreader:
>> Is there a way to make Octave automatically run a particular script every
>> n
>> seconds, where n is user specified? The intent is to check a (financial)
>> website every n seconds for a change in the data hosted on the website
>> and
>> then take some conditional action. I suppose I could write a while loop,
>> but
>> I was wondering if there is a dedicated Octave function/method for this.
>>
>>
>>
>> --
>> Sent from:
>> https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
> I am aware of this, and I have an outstanding query on Stackoverflow about
> this. The link is
> https://stackoverflow.com/questions/60997453/syntax-for-running-octave-script-by-crontab 
>
> --
> -----------------------------------------------------------
> Dr.-Ing. Dieter Jurzitza                    76131 Karlsruhe





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Automatically run a script every n seconds

DigitalHermit
In reply to this post by Dr.-Ing. Dieter Jurzitza
On Sat, Apr 4, 2020 at 4:56 PM Dr.-Ing. Dieter Jurzitza
<[hidden email]> wrote:
>
> Hello babelproofreader,
> in Linux you could put this in a crontab entry.

Crontab works great normally and is valid. In this case, however, it
may not have sufficient timer resolution if it needs to run on
seconds.

If you are running systemd, there is a high-resolution timer
available. (https://www.certdepot.net/rhel7-use-systemd-timers/)

This said, it may be worthwhile to use a loop within Octave. It would
depend on whether the task needs to sync to an external clock or can
use a "sloppy" timer. I.e., if it needs to run at the 5s or 10s after
the minute, then
polling the system clock could work with the caveat that Linux is not
hard real time.  (https://lwn.net/Articles/734694/)




--
"Don't be lazy. Do the thing. Do it properly."  - Simone Giertz


Reply | Threaded
Open this post in threaded view
|

Re: Automatically run a script every n seconds

Francesco Potortì
In reply to this post by babelproofreader
>Is there a way to make Octave automatically run a particular script every n
>seconds, where n is user specified? The intent is to check a (financial)
>website every n seconds for a change in the data hosted on the website and
>then take some conditional action. I suppose I could write a while loop, but
>I was wondering if there is a dedicated Octave function/method for this.

The Octave interpreter is single-threaded (apart from plotting, which is
a different matter), so a loop is perfectly reasonable:

while true
  exec_your_code();
  if (terminate_condition)
    break;
  endif
  pause(n)
endwhile

Note that n can be fractional.

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it