【发布时间】:2015-01-11 10:20:06
【问题描述】:
首先,让我说我对 Cron Jobs 或 PHP 文件一无所知,所以如果您愿意回复,请记住我的新手身份 - (用小词,慢慢说!)
我是我们组织网站的网站管理员,我正在尝试做一些简单但耗时的事情:获取我们网站上的主页,并在感恩节和圣诞节假期期间自动更新它。我已经创建了我需要的特定网页,并将它们上传到 GoDaddy 服务器,但是我真的没有时间进入并随着日子的临近手动重命名页面;有人告诉我,Cron Job 只是用来自动保存现有页面并重命名新页面的东西。
这就是我想要做的: 1) 位于根目录中的文件 Index.htm 被保存或重命名,以便我可以在假期结束后返回它。 2) 现在名为 /Holiday Pages/happy_thanksgiving.htm 的文件于 11 月 25 日移至根目录并重命名为 index.htm 与 12 月 24 日名为 merry_christmas.htm 的文件相同。 3) GoDaddy 有一个 Cron Job 控制面板,它允许我在特定日期的特定时间运行特定脚本,所以我认为不需要将日期代码嵌入到脚本本身中 - 但我没有一个线索在这个脚本中放什么 - 通过与 GoDaddy 的人们交谈,他们建议使用 PHP 脚本。 4)在这个 PHP 脚本中,我需要编写哪些命令(请提供具体示例 - 示例脚本会很棒,非常感谢! 5) 这个脚本的扩展名需要是什么? .TXT 还是 .PHP ??
提前致谢!再一次,请记住我在我的头上 - 请原谅我的无知!
----------------------------------- --------更新 111/15/14 ------------------------ -------------------- 这是我迄今为止尝试过的,使用了您的一些建议 - 数字 1) 2) 等是试用脚本编号,然后由 GoDaddy 的 Cron 作业管理器调用。
1) --------------------------------------------- -
<?php
$target = "/holiday_pages/happy_thanksgiving.html";
$newName = "/holiday_pages/index.htm";
$renameResult = rename($target, $newName);
// Evaluate the value returned from the function if needed
if ($renameResult == true) {
echo $target . " is now named " . $newName;
} else {
echo "Could not rename that file";
}
?>
2) --------------------------------------------- ---
rename('/holiday_pages/happy_thanksgiving.html', '/holiday_pages/index.htm');
3) --------------------------------------------- ---
rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");
?>
4) --------------------------------------------- ---
<?php
$date = new DateTime();
$date -> format('Y.m.d');
if ($date == '2014.11.15') {
copy('./HTML/holiday_pages/index.htm','index.htm.bak');
copy('./HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');
}
5) --------------------------------------------- -----
<?php
$date = new DateTime();
$date -> format('Y.m.d');
if ($date == '2014.11.15') {
copy('../HTML/holiday_pages/index.htm','index.htm.bak');
copy('../HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');
}
6) --------------------------------------------- -----
<?php
$date = new DateTime();
$date -> format('Y.m.d');
if ($date == '2014.11.15') {
copy('/HTML/holiday_pages/index.htm','index.htm.bak');
copy('/HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');
}
7) --------------------------------------------- ------
<?php
$date = new DateTime();
$date -> format('Y.m.d');
if ($date == '2014.11.15') {
copy('./holiday_pages/index.htm','index.htm.bak');
copy('./holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');
【问题讨论】:
-
我已经尝试了几种脚本变体,但到目前为止都没有运气。奇怪的是,我没有收到任何从 Cron 管理器发送到我的电子邮件的错误消息 - 几乎就像没有任何东西在运行,但 Cron 管理器说脚本已启用。我已经检查以确保每个 PHP 文件都有 777 权限,甚至尝试了嵌入我的用户名和密码的变体......仍然无法正常工作。仅供参考,我每个月只有大约 1 小时用于网站维护,所以让这种自动化工作绝对是我的首要任务!