Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

CronJob - to script or not?

Discussion in 'General Discussion' started by whatwasthat, Aug 21, 2013.

  1. whatwasthat

    whatwasthat Registered

    Joined:
    Aug 19, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    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
     
  2. PlotHost

    PlotHost Well-Known Member

    Joined:
    Apr 29, 2011
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    68
    Location:
    Romania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,928
    Likes Received:
    1,819
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. whatwasthat

    whatwasthat Registered

    Joined:
    Aug 19, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    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.
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,928
    Likes Received:
    1,819
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice