Author |
Message |
jakec
Site Admin

Joined: Feb 06, 2006
Posts: 3048
Location: United Kingdom
|
Posted:
Fri Jun 02, 2006 10:40 am |
|
Hi,
I have a php script which when run does a backup of my database and emails it to me.
Now I've been trying setup a cron job using Putty, but I am having a problem.
I've been creating the command in a text file and uploading the file to the root of my space. Then using the command crontab cron.txt to install the command. This works great and I can see the command by using crontab -l, but the script isn't executing.
The command looks like this: 20 * * * * $HOME/name/html/db_backup/backup.php
This is how 1and1 show you how to do it in the FAQ, but it's not for a PHP file, could this be the problem?
I've managed to get it to work by using wget as follows:
20 * * * * wget http://mysite.com/db_backup/backup.php
Obviously this is not ideal, I would like to password protect this directory.
I suspect the problem lies with the path I'm using, or because the script is PHP?
Does anyone have any experience of running cron jobs with 1and1?
Thanks in advance
Jakec |
|
|
|
 |
Tao_Man
Involved


Joined: Jul 15, 2004
Posts: 252
Location: OKC, OK
|
Posted:
Fri Jun 02, 2006 11:42 am |
|
PHP isn't a normal script language, so you just don't run it from the command line in most cases.
This should work if you have PHP 4.3 or newer and may work on older versions
First add
#!/usr/bin/php
to the first line of your php script then change your cron tab to be
20 * * * * ./$HOME/name/html/db_backup/backup.php
if your path is correct then that should work
EDIT: forgot to add you will need to chmod file to be executeable so chmod +x file or chmod 655 or 755 |
_________________ ------------------------------------------
To strive, to seek, to find, but not to yield!
I don't know Kara-te but I do know cra-zy, and I WILL use it! |
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Fri Jun 02, 2006 8:17 pm |
|
You may need to provide the absolute file path rather than $HOME, but certainly give this a try. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
jakec

|
Posted:
Sat Jun 03, 2006 3:26 pm |
|
TM, i've tried what you suggested, but it doesn't appear to have worked. I tried various combinations, but no luck.
How would I find out what the absolute path is? |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Sat Jun 03, 2006 4:24 pm |
|
You should have been advised of the root path as part of your hosting confirmation setup email or if you have cPanel, you should be able to find it in there.
I would agree with Montego though, one normally uses the full path rather than a variable thus;
/home/whatever/public_html/yourscript.txt
Obviously it varies on each server, some use httpdocs instead of public_html etc. |
|
|
|
 |
montego

|
Posted:
Sun Jun 04, 2006 12:22 am |
|
Oooh, and make sure the execute "bit" is turned on permissions-wise... Again, though, it would be important to know what user cron is submitting this under. Hopefully the same as your cpanel/web admin login. |
|
|
|
 |
jakec

|
Posted:
Sun Jun 04, 2006 2:12 am |
|
Unfortunately 1and1 don't use cPanel and they have never given a full path in my emails.
I've emailed 1and1, but I'm still waiting for a reply.
Thanks for your help, if I find the answer I'll post it here. |
|
|
|
 |
Guardian2003

|
Posted:
Sun Jun 04, 2006 2:21 am |
|
jakec wrote: | I've emailed 1and1, but I'm still waiting for a reply.
|
Sadly that is par for the course with 1and1.
Before I had my own servers, many moons ago I did use a little work around...
Set your browser default page to the page you need firing, then use the Windows scheduler to fire up the browser - not ideal but it worked for me. |
|
|
|
 |
jakec

|
Posted:
Sun Jun 04, 2006 7:23 am |
|
The things is I can schedule the job using a cron job, wget, and the http path, but I don't want to do it this way because anyone can run the script.  |
|
|
|
 |
Tao_Man

|
Posted:
Mon Jun 05, 2006 1:24 pm |
|
you may want to run this little script it should give you the full path
<?php
phpinfo();
?>
put that in the same directory as you other script and point your browser it should give you the real and compleate path
it is possable they have comand line mode turned off and there is just know way to do it then other then in a browser |
|
|
|
 |
jakec

|
Posted:
Mon Jun 05, 2006 2:45 pm |
|
Well it looks like the complete path should be something like this:
/kunden/homepages/32/myaccount/htdocs/sitename/html/db_backup/backup.php
Should the directory for PHP be the same as the php.ini file, because that is:
/usr/local/lib/php.ini
or the should it be the include path?
/usr/local/lib/php
Sorry I'm not a PHP coder.
Is there a way of recording any errors to a log file, or something?
Thanks for all your help |
|
|
|
 |
Tao_Man

|
Posted:
Mon Jun 05, 2006 4:29 pm |
|
Well it could be anywhare but I do not think that php would be in /usr/local/lib/php
If not /usr/bin/php I would try /usr/local/bin/php |
|
|
|
 |
Guardian2003

|
Posted:
Tue Jun 06, 2006 9:19 am |
|
Remove the phpinfo file though as soon as you can - you do not want to expose data like that to the world. |
|
|
|
 |
jakec

|
Posted:
Tue Jun 06, 2006 11:02 am |
|
No problem already done.  |
|
|
|
 |
|