Jump to content

Can't seem to get a cronjob to work???


Scooby08

Recommended Posts

Am looking for some help on setting up a simple cronjob.. PHP is installed as CGI.. I simply want to run a php script every minute (30 seconds if possible).. My hosting's through godaddy so I tried using their cron manager first, but the most they allow cron jobs is twice an hour and I need at least every minute..

 

Now I have read many tutorials on this and cant seem to get anywhere so I'm looking for some extra help here..

 

I've been looking at this tutorial: http://www.htmlcenter.com/blog/running-php-scripts-with-cron/

And even this tutorial: http://crunchbang.org/archives/2007/10/26/howto-setup-a-crontab-file/

 

I'm having troubles using the command line and I just need some guidance if possible..

 

Here's where I'm at..

 

I opened the terminal,

typed crontab -e,

tried putting in my command,

 

and from there I don't know how to save it or what needs to be done??? Occasionally it says "-- INSERT --" at the bottom or "recording", but have no idea what that means..

Link to comment
Share on other sites

and from there I don't know how to save it or what needs to be done??? Occasionally it says "-- INSERT --" at the bottom or "recording", but have no idea what that means..

« Last Edit: Today at 13:01:46 by Scooby08 »

 

Sounds like your using vim. Simply type...

 

:wq

 

and hit enter to save. You might want to take a quick look at the vimtutor for a quick vim tutorial. Simply type....

 

vimtutor

 

in a terminal and start reading.

Link to comment
Share on other sites

Thanks Thorpe!

 

That helps a ton.. Got a bit further now..

 

Now, in the command line, it says "You have mail." Seems that each minute I get a new email since that was what I set the cronjob script to do.. But I open that email and it reads this:

 

Could not open input file: /home/content/html/include/cron/cron.php

 

I figured it might be permissions so I ran this: chmod 755 cron.php

 

It still doesnt seem to be working.. Would anybody out there have any ideas as to what I could check on??

Link to comment
Share on other sites

I've tried a few...

 

* * * * * php /home/content/html/include/cron/cron.php

ERROR: Could not open input file: /home/content/html/include/cron/cron.php

 

* * * * * /home/content/html/include/cron/cron.php

ERROR: /bin/sh: /home/content/html/include/cron/cron.php: Input/output error

 

* * * * * /usr/local/bin/php -q /home/content/html/include/cron/cron.php

ERROR: /bin/sh: /usr/local/bin/php: No such file or directory

 

Now that last one I'm not sure that /usr/local/bin/php is correct.. That was what was in the tutorial..

 

Could I be missing something entirely?? Like I'm wondering how this connects to the file on the server that runs the script? Wouldn't it need some sort of a username password set up?

Link to comment
Share on other sites

Cron jobs are executed via your shell, so, you need to tell your shell to execute your php scripts using the php command line interface.

 

The last line you posted is probably closest to what you need, however it would appear the php command line executable is somwhere else on the system.

 

Open a terminal and type.....

 

whereis php

 

This should give you the full path to the php command line executable, you can then replace /usr/local/bin/php with it.

Link to comment
Share on other sites

Here's what I got..

 

* * * * * /usr/bin/php -q /home/content/html/include/cron/cron.php

ERROR: Could not open input file: /home/content/html/include/cron/cron.php

 

So that part is correct now.. Not sure about the script path though..

 

I found this inside godaddy's cron settings.. Maybe this might have some helpful info:

 

 

The Command field is the script or executable that runs at a specified frequency. Click Browse to locate a file in your hosting account. The full file name of your selection is placed into this editable field.

 

Cron commands are typically script files that have executable permission and specify their interpreter as the first line of the file. For example, a first line of "#!/usr/bin/perl" directs the system to run the perl language interpreter for the file.

 

Your Shared Hosting account supports the following languages and associated interpreter lines:

 

    * Perl: #!/usr/bin/perl

    * Python 2.2: #!/usr/bin/python2.2

    * Python 2.3: #!/usr/bin/python2.3

    * Python 2.4: #!/usr/bin/python2.4

    * Ruby: #!/usr/local/bin/ruby

    * Bash: #!/bin/bash

 

The installed versions of PHP 4 and PHP 5 do not support the interpreter specification in a PHP file. In order to run a PHP script via Cron, you must specify the interpreter manually. For example:

 

    * PHP 4: /web/cgi-bin/php "$HOME/html/test.php"

    * PHP 5: /web/cgi-bin/php5 "$HOME/html/test.php5"

 

Note: In this example script, "$HOME" represents the full path to your Shared Hosting account. The actual path to your account will be provided if you select the script from your account using the Browse button.

Link to comment
Share on other sites

Yeah, the path to your file doesn't look correct. Most setups create a user directory within the /home directory, but they can sometimes work in hierarchies too.

 

Anyway, you would be best to follow the advice and use the $HOME variable within your crontab entry. eg;

 

* * * * * /usr/bin/php -q $HOME/content/html/include/cron/cron.php

Link to comment
Share on other sites

Ok, well that now sounds like a permissions issue. make sure the file is chmod'd at least 755. Also, assuming html is your vhosts document root you should probably move this cron.php file to somewhere that is not web accessible.

 

Place it within your $HOME directory and see how you go.

 

mv html/include/cron/cron.php ~/cron.php

 

You should probably also use a shebang within your php script. eg: Place this in the very first line of your script (before the <?php tag)....

 

#!/usr/bin/php

 

Your crontab entry would then need only look like.

 

* * * * * $HOME/cron.php

Link to comment
Share on other sites

Just using it to grab the latest xml file and update mine.. Just doing this to load the xml file quicker.. I can't figure out any other way to load xml files quicker then if I have a local copy.. I'm open to any suggestions here...?..?

 

<?php
$lines = file_get_contents('http://www.externalsite.com/livelines.xml');
file_put_contents('http://www.site.com/include/cron/lines.xml',$lines);
?>

 

Oh yeah.. And I don't have access outside the root directory through godaddy..

 

 

Link to comment
Share on other sites

Why would that be not found? Isn't /Users/myusername my computer and not the server?

 

Why would it be your computer? You are executing these commands within a remote shell?

 

Next, unless your username is myusername, that path is not correct.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.