javascript - How do i run same script over and over, with delay between each run?
问题描述
in order to run a same script multiple times, i currently use ;
For example, i will run something like this
node RocketLaunch.js;node RocketLaunch.js;node RocketLaunch.js
This works great and run my script 3 times back to back. I am wondering is there an easy way i can run these 3 with gap of 1 hour?
Edit - Thank you for the responses, i am new to learning programming so apologize for posting this in JS, since it seems like a non JS question.
More information - The way i want to intend to use it, run this script every 1 hour for lets say 20 hours/times. The entire job takes around 5 minutes after i run the script and i want it to run every hour and do that 5 minutes job.
So perhaps run a command at Bash level, where i can type it 20 times with a delay of an hour. It runs every hour for 20 hours, then i can do the whole thing again.
解决方案
This is how I typically do this in bash:
for x in {1..3};
do
node RocketLaunch.js
sleep 3600
done
The {1..3}
tells the for loop to do this 3 times, and the sleep function takes the number of seconds as its argument. (3600 = 60 seconds * 60 minutes)
推荐阅读
- bash - gawk gensub 中 (GNU coreutils) 日期的命令替换
- excel - 如何按 ID 将列分组为一行
- installation - ansible塔安装问题
- postgresql - 可以交错varbits吗?
- c - 我如何摆脱这些数字
- flutter - 延迟地理定位器
- ruby-on-rails - 使用 cancancan 的 3 类角色的授权问题
- ios - 在哪里可以找到使用 URL 下载的文件?
- jpa - JPA 存储库 - 返回当前日期时间之前的实体
- c - linux内核更新导致堆在linux 5.10上不可执行但在linux 5.0上可执行而NX(DEP)禁用的哪个功能