Cron Job to rename web pages

First, let me say that I know nothing about Cron Jobs or PHP files, so please keep my newbie status in mind if you are kind enough to reply - (use small words and speak slowly!)

I am the webmaster for our organization's site, and I am trying to do something which should be simple, yet time consuming: Take the main web page on our site and automatically update it during the Thanksgiving and Christmas Holidays. I have already created the specific web pages that I need, and uploaded them to the GoDaddy server, but I really don't have the time to go in and manually rename the pages as the days approach; I'm told that a Cron Job would be just the thing to use to automatically save the existing page and rename the new page.

Here is specifically what I want to do: 1) The file Index.htm, located in the root directory, gets either saved or renamed so that I can go back to it after the Holidays are over. 2) The file now named /Holiday Pages/happy_thanksgiving.htm gets moved to the root directory on November 25th and renamed index.htm Same thing with the file named merry_christmas.htm on December 24th. 3) GoDaddy has a Cron Job control panel which allows me to run a specific script on a certain day at a certain time, so I don't think the date codes would need to be embedded into the script itself - but I've not a clue what to put in this script - from talking to the folks at GoDaddy, they suggest a PHP script. 4) Within this PHP script, exactly what commands would I need to write (specific examples please - a sample script would be awesome and MOST appreciated! 5) What would the extension on this script need to be? .TXT or .PHP ??

Thanks in advance! Again, please remember that I'm in over my head here - and pardon my ignorance!

-------------------------------------------------------UPDATE 111/15/14 -------------------------------------------------------- Here's what I have tried so far, using some of your suggestions - the numbers 1) 2) etc are trial script numbers which were then called by the GoDaddy's Cron Job Manager.

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');

Better solution is create the files and code dynamically include file according to the date, example code is given below:

$date = date("m-d-y", time());  // current date

$holidays = array('12-25-14' => 'christmas-page.php', '11-27-14' => 'thanksgiving-day-page.php'); // create all holidays here

$page = isset($holidays[$date]) ? $holidays[$date] : 'default-index.php';

include($page);

Simple logic, will work fine


Just create a file and name it, for example holiday_copy.php. Here is the script itself:

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.25') {
    copy('index.htm','index.htm.bak');
    copy('../Holiday Pages/happy_thanksgiving.htm','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');
}
else if ($date == '2014.12.24') {
    copy('index.htm','index.htm.bak');
    copy('../Holiday Pages/merry_christmas.htm','index.htm'); // again, you need to make sure if this (../Holiday Pages/) is the right path to your file!
}
else if ($date == '2014.12.27') {
    copy('index.htm.bak','index.htm');
}

?>

you have to run this script on the desired days, best will be at

0:01 on eg 2014-12-24

You need to place this file in the root directory, where your index.htm is located. If you don't want this, add the appropiate path to all the copied files inside this script - eg here:

copy('index.htm','index.htm.bak');

Be sure to have the rights to access all the directories and files! Remember to call it on the days after the holiday in order to get your old index.htm back.


This is not a PHP solution. This is a SSH/Command Line solution, Nor is it a Cron Job. Takes about 2-5 minutes.

Assuming you are on a Linux hosting plan, and that SSH (remote log in) is enabled for your account; If not, you can ask/call GoDaddy to enable this feature for your account.

Once you are on the command line, do the following.

Safety first, so backup all the files we are gonna move around or mess with:

  • cd PUBLIC_ROOT_DIR
  • cp "index.htm" "index.htm.bak"
  • cp "Holiday Pages/happy_thanksgiving.htm" "Holiday Pages/happy_thanksgiving.htm.bak"
  • cp "Holiday Pages/merry_christmas.htm" "Holiday Pages/merry_christmas.htm.bak"
  • Before thanksgiving:

  • cd PUBLIC_ROOT_DIR
  • mv "index.htm" "index.htm.off"
  • mv "Holiday Pages/happy_thanksgiving.htm" "index.htm"
  • After thanksgiving:

  • cd PUBLIC_ROOT_DIR
  • mv "index.htm" "happy_thanksgiving.htm.off"
  • mv "index.htm.off" "index.htm"
  • Before Christmas:

  • cd PUBLIC_ROOT_DIR
  • mv "index.htm" "index.htm.off"
  • mv "Holiday Pages/merry_christmas.htm" "index.htm"
  • After Christmas:

  • cd PUBLIC_ROOT_DIR
  • mv "index.htm" "merry_christmas.htm.off"
  • mv "index.htm.off" "index.htm"
  • 链接地址: http://www.djcxy.com/p/66344.html

    上一篇: 时区和克朗

    下一篇: Cron作业重命名网页