The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    253
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    US
    cPanel Access Level:
    Root Administrator
    Twitter:
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    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.
     
  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:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    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.
     
Loading...

Share This Page