How do run a Unix command at a given time interval?

大兔子大兔子 提交于 2019-12-06 06:21:52

问题


I want to run a Unix command (e.g. ls) at 5 minute intervals through a script.

Explanation:

I have a Unix script. In that script I have a command called "ls".

I want that "ls" command to run every 5 minutes from that script.


回答1:


Use watch. The -n flag specifies interval in seconds, so

watch -n 300 ls



回答2:


while true; do
    ls
    sleep 300
done

?




回答3:


Put your script into the Crontab via

crontab -e

More information about Cron you can find at wikipedia




回答4:


You could use crontab for example. See http://en.wikipedia.org/wiki/Cron

for example i you want to run your script every five minutes via crontab it should look something like this:

#m  h dom mon dow user command
*/5 * *   *   *   root /path/to/script



回答5:


crontab 

http://en.wikipedia.org/wiki/Cron

or

svc 

http://cr.yp.to/daemontools.html



来源:https://stackoverflow.com/questions/6758500/how-do-run-a-unix-command-at-a-given-time-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!