Scooby08 Posted December 28, 2009 Share Posted December 28, 2009 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.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 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?? Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 What does your crontab entry look like? Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 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 Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 Well I guess godaddy just doesn't want cron jobs ran every minute.. They must be blocking them or something.. I don't suppose you'd have any other ideas that could do something similar to a cron job?? ha Thanks for the help thorpe! Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 Well I guess godaddy just doesn't want cron jobs ran every minute.. They must be blocking them or something.. Why? What errors are you getting now? Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 It gave me an error with $HOME being set as "/Users/myusername" * * * * * /usr/bin/php -q $HOME/html/include/cron/cron.php Could not open input file: /Users/myusername/html/include/cron/cron.php Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 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 Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 By not web accessable are you meaning to put that file outside of the root directory? Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 By not web accessable are you meaning to put that file outside of the root directory? Yes. Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 Actually, what does this script actually do? You may not even need php at all. Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 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.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 You don't need php for that. Place this within your crontab file.... * * * * * cd $HOME/html/include/cron && /usr/bin/wget http://www.externalsite.com/livelines.xml Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 Sorry, I didn't see the local file name was different to that of the remote one. * * * * * cd $HOME/html/include/cron && /usr/bin/wget -O lines.xml http://www.externalsite.com/livelines.xml Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 So now I get this: (using your first way, I dont care about the filename) /bin/sh: line 0: cd: /Users/myusername/html/include/cron: No such file or directory Why would that be not found? Isn't /Users/myusername my computer and not the server? Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted December 28, 2009 Author Share Posted December 28, 2009 tried another /bin/sh: line 0: cd: /home/content/html/include/cron: Not a directory I have to be missing something.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.