1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

cant get cron to work

Discussion in 'PHP' started by piniyini, Sep 29, 2005.

  1. #1
    I am trying to get a file to work using cron but its just not happening, this is what I have in the command section

    /home/desiouk1/public_html/filename.php
    Code (markup):
    any know what I am doing wrong?

    the reason I want to use cron is so I can have a backup of the database

    I can get the following code to work with php but not on cron

    mysqldump --user=desiouk1 --password=**** desiouk1_desiguy --quick --result-file=/home/desiouk1/etc/db_backup.sql
    Code (markup):
     
    piniyini, Sep 29, 2005 IP
  2. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try something like this, (confirm the location of the php executable on your server):

    
    /usr/local/bin/php -q /home/desiouk1/public_html/filename.php
    Code (markup):
     
    JoeO, Sep 29, 2005 IP
  3. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #3
    thanks for replying joeo, i've tried your suggestion and it doesnt work for me

    how do i find the php executable location on my server? will it be on phpinfo()?
     
    piniyini, Sep 29, 2005 IP
  4. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #4
    If it is just a PHP page you want to get parsed, and you do not have the command line PHP compiler installed, you can also just let curl,lynx or any other tool fetch that page:

    curl http://www.mydomain.com/filename.php
     
    frankm, Sep 29, 2005 IP
    piniyini likes this.
  5. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #5
    ugh, i'm a n00b with all this so please can you explain in laymans terms? i've got cron (i'm using cpanel) and am trying to use that to run a file periodically.

    if i enter

    curl http://www.mydomain.com/filename.php

    into cron does that mean it will work?
     
    piniyini, Sep 29, 2005 IP
  6. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #6
    ah , sorry for the tech-talk piniyini, as you were talking about cronjobs I assumed you know a bit :)

    1) your first option is using the php command line tool, but that is not standard installed on a server when installing apache+php+mysql. so first check if you have it installed somewhere in /usr/bin or /usr/local/bin (using ftp or so)

    2) if you do not have php (command line) instaled, you can let a tool fetch the url every hour. There are several tools that do that: curl, lynx, wget etc.
    e.g. if you create a cron entry: lynx -dump -source http://www.domain.tld/file.html , file.html will be downloaded.

    hope this helps ..
     
    frankm, Sep 29, 2005 IP
  7. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #7
    On my server I found the location of the php executable using "php -info"... I am not sure if this is standard for every server.
    I just setup my first cron job a couple days ago, took me a while, wget or lynx didn't work for me.
    I needed to run the command line php.
     
    JoeO, Sep 29, 2005 IP
  8. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #8
    @JoeO:

    to find the exact path to an executable you can use: which php
    it will return the path
     
    frankm, Sep 29, 2005 IP
    JoeO likes this.
  9. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #9
    lol thanks frank... I really should learn some more basic unix commands, that would have saved me a headache the other day :)
     
    JoeO, Sep 29, 2005 IP
  10. michele

    michele Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You could try putting your back up command in a shell script and run that from cron. To do that, you would copy the code below into a plain text file, name it something like 'backup.sh', and then upload to server.
    This could be enhanced to add a unique date to backup file name, or to email you the file etc etc.

    ---------------------------

    #!/bin/sh

    mysqldump \
    --user=desiouk1 \
    --password=**** \
    desiouk1_desiguy \
    --quick \
    --result-file=/home/desiouk1/etc/db_backup.sql
     
    michele, Sep 29, 2005 IP
  11. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #11
    I'll try all your suggestion later as I'm in uni at the mo and cant access cpanel from these servers.

    Will get back to you all. Ta
     
    piniyini, Sep 30, 2005 IP
  12. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #12
    Now this is really getting on my nerves :mad:

    frankm, no I dont have any on those folders in my ftp and the second point you mentioned is not working for me in cron.

    michele, I understand what you are saying but I cant run a file through cron! Is there anyway my host could have cron but not have it active?

    :confused:
     
    piniyini, Sep 30, 2005 IP
  13. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #13
    @piniyini:
    do you have shell access to this server? would make life a lot easier for you :)
     
    frankm, Sep 30, 2005 IP
  14. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    It is possible that your server is not set up to run php scripts from the command line, I had to install something to get that to work on mine, but cannot remember what exactly it was... Anyways.. try this.

    <?php 
    $whereisphp = `which php`;
    echo $whereisphp;
    echo "<p></p>";
    $phpversion = `php -v`;
    echo $phpversion;
    ?>
    PHP:
    Make a file called whatever.php and then open that in your browser. That will tell you exactly where php is.. usually in /usr/bin/ or /usr/local/bin/
    If you get something in return from the php -v command then i think that'll mean you can run php from the command line...

    I have been able to run php scripts from cron using cpanel with the following

    php /full/path/to/phpscript/script.php
    Code (markup):
    Hope that helps...
     
    rederick, Sep 30, 2005 IP
  15. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #15
    rederick, this is what I get when I run the script

    /usr/local/bin/php

    PHP 4.3.11 (cli) (built: May 23 2005 18:24:54) Copyright (c) 1997-2004 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with Zend Extension Manager v1.0.8, Copyright (c) 2003-2005, by Zend Technologies with Zend Optimizer v2.5.10, Copyright (c) 1998-2005, by Zend Technologies


    I have tried all sorts to get cron to work but to no avail, I'll send an email to my host

    thanks for everything guys, I'm gonna get to the bottom of this!
     
    piniyini, Oct 1, 2005 IP
  16. myeffort

    myeffort Peon

    Messages:
    3
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Maybe you can try chmod the script file to 755. Sometimes that help.
     
    myeffort, Oct 3, 2005 IP
  17. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #17
    If you have shell access, you can use
    crontab -l
    Code (markup):
    to check what commands your user has installed in cron.
    If you post the results of that command here, maybe we could help if it was a syntax error or something.
     
    johnt, Oct 3, 2005 IP
  18. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #18
    My host sure is funny ...

    and all that testing I did, wastin ma time!! :mad:
     
    piniyini, Oct 3, 2005 IP
  19. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I'd be looking for a new host if the cron can be down that long without them doing anything. Or at least constantly check up on it to make sure it is still running.
     
    JoeO, Oct 3, 2005 IP
    piniyini likes this.
  20. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #20
    Both things I wanted to do with cron are now working, thank you very much to all you guys! ;)

    and Joe, I am waiting for my hosting to expire (don't hear that everyday) and then, poof - I'll be gone. :p
     
    piniyini, Oct 3, 2005 IP