javascript - 基本的 cron 作业问题

标签 javascript html insert cron jobs

我的 HTML 文件中有一个特定的脚本,我想使用 cron 作业每 24 小时运行一次。我的问题是我应该在托管商(主机)命令中输入什么路径。

我是否输入 php/path/to/index.php 因为这不会每 24 小时运行一次我的整个代码,我想知道如何每 24 小时运行一个特定的脚本。

附件是我的代码,提前谢谢您!!

<html>
<head>
		<link href="style.css" rel="stylesheet" type="text/css"/>	
</head>

<body>

<div id="header">
<h1>City Gallery</h1>
</div>

<div id="sidebar">

</div>

<div id="maincontent">
<h1>Rumours</h1>




<table id="myTable" width"100%">

  <tr>
    <th width="30%">From</th>
    <th width="30%">Player</th>   
    <th width="40%">Price</th>
  </tr>

  <tr>
    <td></br></td>
    <td></br></td>    
    <td></br></td>
  </tr>
</table>

<script>

// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");

// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(0);

// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);

// Add some text to the new cells:
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
cell3.innerHTML = "NEW CELL3";
</script>



</div>

<div id="rightbar">
</div>

<div id="footer">
</div>

</body>
</head>
</html>

最佳答案

在您的 cron 作业脚本中使用 cURL 或 wget,并使用 localhost 作为您获取的 URL 中的主机名。这样,您将通过运行 PHP 的 Web 服务器(通常是 Apache,但不一定)调用您的网页。

您必须设置一个特定的网页/URL 来完成您希望脚本每 24 小时完成的任务。

例如,您的 cron 脚本(位于 website-cron.sh 中)可能是:

#! /bin/sh

/usr/bin/curl --silent --show-error http://localhost/cron-script.php/parameters

您可以使用 crontab -e 将其放入 crontab 文件中,并输入此行以在每天凌晨 3:00 运行脚本:

0 3 * * *   /path/to/website-cron.sh

关于javascript - 基本的 cron 作业问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30646815/

相关文章:

javascript - 为什么我不能在 FancyBox 中使用 javascript 变量?

javascript - 如何在新的analytics.js API中添加像_addOrganic这样的搜索引擎?

javascript - 如果元素 id 被定义为 php 函数,如何编写 jquery append $ ("#id").append() 语句?

node.js - 使用 sequelize POST 方法在 nodejs 中插入新记录

javascript - JS中如何将Object设置在Array之前?

javascript - 使用 jQuery 删除 HTML 表格行

javascript - 在不同的屏幕尺寸下动态改变另一个 div 的位置

php - 无法在数据库中插入必填字段

sql-server - 如何使用 DBeaver 创建 SQL Server 存储过程?

javascript - Angular - ui-router 状态不被识别