基本的cron工作问题(Basic cron job issue)

编程入门 行业动态 更新时间:2024-10-14 22:17:16
基本的cron工作问题(Basic cron job issue)

我的HTML文件中有一个特定的脚本,我希望每24小时使用一个cron作业运行。 我的问题是我进入hostinger(host)命令的路径是什么。

我是否输入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> 
  
 

I have a particular script in my HTML file that I want to run every 24 hours using a cron job. My question is what path do I enter into my hostinger (host) command.

Do I enter php /path/to/index.php because won't that run my whole code every 24 hours, I want to know how to run a specific script every 24 hours.

Attached is my code, thank you in advance !!

<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中的主机名。 这样,您将通过Web服务器(通常是Apache,但不一定)调用您的网页,这将运行PHP。

您必须设置特定的网页/ URL,以执行您希望脚本每24小时完成的操作。

例如,您在web-cron.sh中的cron脚本可能是:

#! /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

Use cURL or wget in your cron job script, with localhost as the hostname in the URL that you fetch. That way, you'll be invoking your web page via the web server (typically Apache, but not necessarily), which will run PHP.

You'll have to set up a particular webpage/URL to do what you want the script to accomplish every 24 hours.

For example, your cron script, in website-cron.sh, could be:

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

You could put this in your crontab file using crontab -e and entering this line to run the script at 3:00am every day:

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

更多推荐

本文发布于:2023-07-27 20:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1295045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   cron   Basic   issue   job

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!