嗯,这取决于您是否可以在命令行 (CLI) 中运行 php,或者不能在服务器上运行。您可能需要找到php 可执行文件的路径,因为它可能未在PATH 中设置。
如果是,那么我将使用 php update-index.php 运行一个自制脚本,该脚本会重新生成您的 index.html 文件。
如果您无法在 CLI 中运行 PHP,那么您可以将此脚本放在您的网站上并使用 curl 或 wget 调用它。您可以使用 Apache 规则或仅通过检查 POST 参数的存在来保护它,如下所示:
<?php
define('API_KEY', '732hCwhjK');
// If the key is missing then just stop execution.
if (!isset($_POST['key']) || $_POST['key'] !== API_KEY) {
die();
}
// TODO: update your index.html file with Smarty.
// Don't print anything so that the cron doesn't send any mail.
// If you get an error then print it here.
// Cron will then send you the mail with the content printed out.
cron 配置文件示例:
MAILTO="your.mail@example.com"
# CRON TASKS SYNTAX
# -----------------
#
# Output dumper: >/dev/null 2>&1
#
# Multiple values with commas: 5,25,45
#
# Every X intervals: */10 * * * * for every 10 minutes
#
# Aliases: @reboot = run once at startup
# @hourly = 0 * * * *
# @daily = 0 0 * * *
# @weekly = 0 0 * * 0
# @monthly = 0 0 1 * *
# @yearly = 0 0 1 1 *
# Execute update-index.php twice a day, at 6am and 6pm:
0 6,18 * * * /bin/php /home/user/www-data/site/update-index.php 2>&1
# Execute update-index.php via calling the URL at 3am.
# Key is sent via POST to avoid having it visible in the log files.
0 3 * * * wget -O - -q -t 1 --post-data="key=732hCwhjK" "https://your-site.com/update-index.php"
编辑 cron 选项卡
crontab -e -u username
如果你想定义编辑器(nano 或 vim),前缀 EDITOR=xxxx 如下:
EDITOR=vim crontab -e
用户 crontab 文件在这里:
/var/spool/cron/crontabs/
Crontab 文件也可以存储在:
/etc/cron.d/
/etc/cron.hourly/
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/
它们在以下时间运行:
grep run-parts /etc/crontab
或者只是检查所有内容:
less /etc/crontab