简体   繁体   中英

Basic cron job issue

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> 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM