如何将cron作业从php smarty index.tpl保存到index.html?

llew8vvj  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(281)

我想保存一些服务器资源,并从每天更新的smarty template index.tpl创建一个静态index.html文件。
要实现这一点,制作cron作业的最佳方法是什么?

ru9i0ody

ru9i0ody1#

这取决于您是否可以在服务器上的命令行(cli)中运行php。您可能需要找到到的路径 php 可执行文件,因为它可能未在 PATH .
如果是的话,我会用 php update-index.php 这就是再生你的生命的工作 index.html 文件
如果无法在cli中运行php,则可以将此脚本放在网站上,并使用 curlwget . 您可以使用apache规则或通过检查查询参数的存在来保护它,如下所示:

<?php

define('API_KEY', '732hCwhjK');

// If the key is missing then just stop execution.
if (!isset($_GET['key']) || $_GET['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.

0 3 * * * wget -O - -q -t 1 "http://your-site.com/update-index.php?key=732hCwhjK"

编辑cron选项卡 crontab -e -u username 如果要定义编辑器(nano或vim),请以editor=x作为前缀: 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

相关问题