开发者

looping a statement in ubuntu terminal

开发者 https://www.devze.com 2023-02-20 09:07 出处:网络
In the Ubuntu terminal, how do I loop a command like python myscript.py so that it runs every 15 minute开发者_如何学Cs?you are looking for crontab rather than loop.If you really need to schedule s

In the Ubuntu terminal, how do I loop a command like

python myscript.py

so that it runs every 15 minute开发者_如何学Cs?


you are looking for crontab rather than loop.


If you really need to schedule something, then you want crontab.

But if this is temporary (i.e. checking to see if a file has appeared or whatever), then here's how you could do this

while true ; do python myscript.py ; sleep 15m; done

This will execute forever ("while true") so you'll have to ctrl-c to cancel it when you are done.


Sounds like you want to use something like cron instead, but... if you are sure you want something to run in the same terminal-window every N minutes (or seconds, actually), you could use the 'watch' command.

watch -n 60 python myscripy.py


using crontab you can add an entry like */15 * * * * python /path/to/myscript.py

0

精彩评论

暂无评论...
验证码 换一张
取 消