How can I make a bash command run periodically?

前端 未结 8 1942
执笔经年
执笔经年 2020-12-07 20:26

I want to execute a script and have it run a command every x minutes.

Also any general advice on any resources for learning bash scripting could be really cool. I us

相关标签:
8条回答
  • 2020-12-07 20:49

    I want to execute the script and have it run a command every {time interval}

    cron (https://en.wikipedia.org/wiki/Cron) was designed for this purpose. If you run man cron or man crontab you will find instructions for how to use it.

    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.

    If you are comfortable working with bash, I recommend reading through the bash manpage first (man bash) -- there are lots of cool tidbits.

    0 讨论(0)
  • 2020-12-07 20:50

    If you want to run a command periodically, there's 3 ways :

    • using the crontab command ex. * * * * * command (run every minutes)
    • using a loop like : while true; do ./my_script.sh; sleep 60; done (not precise)
    • using systemd timer

    See cron

    Some pointers for best bash scripting practices :

    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/

    0 讨论(0)
提交回复
热议问题