CronJob using php

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
kjason
Forum Newbie
Posts: 3
Joined: Wed Jan 21, 2009 7:11 am

CronJob using php

Post by kjason »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.[/color]


May I ask for a help???

Code: Select all

<?php
$file = '/home/xxxx/public_html/index.htm';
$newfile = '/home/xxxx/public_html/bkb/2009/01/index.htm.bkb';
if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
else
{
    echo "Index Copied";
}
So the file copied and named index.htm.bkb, please I need some help to let the name to be like that the date.index.htm.bkb
Where the date in this format d.m.y
Thanks in advance


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.[/color]
machinehead933
Forum Newbie
Posts: 7
Joined: Tue Jan 20, 2009 10:48 pm

Re: CronJob using php

Post by machinehead933 »

This can be done through the use of PHP's date function:

http://us.php.net/date

Change your line:

Code: Select all

$newfile = '/home/xxxx/public_html/bkb/2009/01/index.htm.bkb';
To:

Code: Select all

$newfile = '/home/xxxx/public_html/bkb/2009/01/' . date('d.m.y') . '.index.htm.bkb';
You can also use the date() function to determine the current date automagically, and determine what the file path should be on the fly.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: CronJob using php

Post by VladSun »

I would use the appropriate language - bash ;)
backup.sh

Code: Select all

#!/bin/bash
cp $1 $2/`date +'%d.%m.%y'`.$1.bkb
Usage:

Code: Select all

backup.sh file destination_directory
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply