How to run when you turn on the computer script that repeats the same command every N seconds?
3 answers
Use the regular cron scheduler, read the console man crontab
- oneAnd if you need a frequency of less than a minute? - cheops
- Yes, run it in the background in an eternal loop, let the interval itself track and wake up when necessary. - PinkTux pm
- 3@cheops here is the answer at stackoverflow.com/questions/9619362/β¦ - perfect
- one@perefect, well, if there is nothing better, you can, though the accuracy will be - plus or minus bast (or rather, a few seconds). - cheops
- @cheops the native function
sleepused there and there is no difference where to push it in kroner or in the script. And bastard, and so it will all depend on the response of the executable binary and the system load. - perfect
|
for Ubuntu 15.04 and older, you can use systemd / Timers
|
if n is equal to, for example, 10 seconds, then you can create, for example, six cron-tasks (running every minute - this is the minimum interval supported by popular implementations of the crond program), the second of which is executed with a delay of 10 seconds, the third - 20, and etc .:
* * * * * /ΠΏΡΡΡ/ΠΊ/ΡΠΊΡΠΈΠΏΡΡ/ΠΈΠ»ΠΈ/ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ΅ ΠΎΠΏΡΠΈΠΈ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ * * * * * sleep 10; /ΠΏΡΡΡ/ΠΊ/ΡΠΊΡΠΈΠΏΡΡ/ΠΈΠ»ΠΈ/ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ΅ ΠΎΠΏΡΠΈΠΈ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ * * * * * sleep 20; /ΠΏΡΡΡ/ΠΊ/ΡΠΊΡΠΈΠΏΡΡ/ΠΈΠ»ΠΈ/ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ΅ ΠΎΠΏΡΠΈΠΈ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ... other methods:
- on ru.so :
- on other so sites:
- Running a cron every 30 seconds
- How to run Cronjobs more often than once per minute?
- How to get a unix script to run every 15 seconds?
- How to run scripts every 5 seconds using cron?
- Cron running job every 15 seconds
- How can I schedule a cron job that runs every 10 seconds in linux?
- Can I run a cron job more frequently than every minute?
- ...
|
cronIf it is less than or not a multiple of a minute, then you need to do your service that will run the script at the intervals you need - Tunker