如何让bash命令定期运行? [英] How can I make a bash command run periodically?
问题描述
我想执行一个脚本,并使其运行一个命令每隔x分钟。
I want to execute a script and have it run a command every x minutes.
同样在学习bash脚本编程的任何资源任何一般性的建议可能是真的很酷。我用Linux对我个人发展的工作,所以的bash脚本并不完全陌生的我,我只是还没有从头开始编写任何我自己的。
Also any general advice on any resources for learning bash scripting could be really cool. I use Linux for my personal development work, so bash scripts are not totally foreign to me, I just haven't written any of my own from scratch.
推荐答案
如果您想定期运行命令,有2种方式:
If you want to run a command periodically, there's 2 ways :
- 使用
的crontab
命令前。* * * * *命令
(运行每分钟) - 使用循环,如:
而真实的;做./my_script.sh;睡60;完成
(未precise)
- using the
crontab
command ex.* * * * * command
(run every minutes) - using a loop like :
while true; do ./my_script.sh; sleep 60; done
(not precise)
请参阅的cron
一些指点最佳bash脚本编程做法:
Some pointers for best bash scripting practices :
http://mywiki.wooledge.org/BashFAQ 结果
指南: http://mywiki.wooledge.org/BashGuide 结果
参考: http://www.gnu.org/software/bash/manual/bash html的结果
http://wiki.bash-hackers.org/ 结果
使用更QUOTES !: http://www.grymoire.com/Unix/Quote.html结果
脚本和更多: http://www.shelldorado.com/
http://mywiki.wooledge.org/BashFAQ
Guide: http://mywiki.wooledge.org/BashGuide
ref: http://www.gnu.org/software/bash/manual/bash.html
http://wiki.bash-hackers.org/
USE MORE QUOTES!: http://www.grymoire.com/Unix/Quote.html
Scripts and more: http://www.shelldorado.com/
这篇关于如何让bash命令定期运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!