Page 1 of 1

CronJob using php

Posted: Wed Jan 21, 2009 7:19 am
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]

Re: CronJob using php

Posted: Thu Jan 22, 2009 11:35 am
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.

Re: CronJob using php

Posted: Thu Jan 22, 2009 1:04 pm
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