dongyuelian9602 2014-06-16 13:41
浏览 52
已采纳

如何为bash脚本指定运行时间?

I was looking for a way to continuously run a PHP script every 15 seconds online, so that I may manage some accounts using an API. I was able to find a script that satisfies what I was looking for as follows:

#!/bin/bash
#This script runs every 15 seconds
#This script is ran in /etc/rc.local (startup)

while (sleep 15 && php test.php) &
do
    wait $!
done 

This script works perfectly and runs every 15 seconds. However, now I want to modify the script such that it may

  1. do what the script is already doing
  2. run a second script, every 5 minutes

Is there a way to modify the current while loop so that I may achieve this? Thanks!

  • 写回答

3条回答 默认 最新

  • duanli0453 2014-06-16 13:55
    关注

    There are much better ways to do this because PHP requires and HTTP request to run that file.

    1. Run a cron job to run this request every set interval (not recommended)
    2. Use another program like python which can run a daemon to do this
    3. Do the calculation every time the page is requested (recommended and almost always possible)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退