dongyuelian9602 2014-06-16 05: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 05: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了