whatwasthat

Registered
Aug 19, 2013
1
0
1
cPanel Access Level
Root Administrator
Hi cPanel experts,

I have a client that uses cPanel. I want to run a daily job to copy a file if it exists to back it up.
Some logic is required.

if file_exists(a){
copy a to b
} else {
//do nothing
}

I would write this in PHP and execute it as a cronjob, if I knew how to do that.
Or should I create an .sh file (upload via FTP only available) and execute that?

Don't have access to SSH.
Thoughts?

Thanks

Craig
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello :)

Yes, you can use the PHP: copy function if you prefer to use PHP. Or, you could utilize a shell file if you are more comfortable with that. Cron jobs are run in the jailed shell environment.

Thank you.
 

whatwasthat

Registered
Aug 19, 2013
1
0
1
cPanel Access Level
Root Administrator
Thanks PlotHost/ cPanelMicheal,

I am happy in either, but PHP would be easiest.
So the question is, how do I make the PHP file run.
Do I just put the local server address of the PHP file into the command box in cPanel?
This will then activate and run that file with permissions of the cronjob user?

Do I need to do anything with permissions?
In the PHP file, do I need to use full URI file locations, or use relative locations? Relative to the php file location, or relative to the cronjob running location? what is that? or should I use "/"?

Thanks so much for your help.
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Here is an example of a cron job command that runs a PHP script:

Code:
php /home/username/public_html/file.php
You should be able to keep the standard 0644 permissions and user ownership on the PHP file. I recommend using the full path to the files that you intend to copy (e.g. /home/username/file.name).

Thank you.