Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
jakec
Site Admin



Joined: Feb 06, 2006
Posts: 3048
Location: United Kingdom

PostPosted: Fri Jun 02, 2006 10:40 am Reply with quote

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 [ Only registered users can see links on this board! Get registered or login! ]

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
 
View user's profile Send private message
Tao_Man
Involved
Involved



Joined: Jul 15, 2004
Posts: 252
Location: OKC, OK

PostPosted: Fri Jun 02, 2006 11:42 am Reply with quote

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! 
View user's profile Send private message Visit poster's website
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Jun 02, 2006 8:17 pm Reply with quote

You may need to provide the absolute file path rather than $HOME, but certainly give this a try.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
jakec







PostPosted: Sat Jun 03, 2006 3:26 pm Reply with quote

TM, i've tried what you suggested, but it doesn't appear to have worked. I tried various combinations, but no luck. Sad

How would I find out what the absolute path is?
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Sat Jun 03, 2006 4:24 pm Reply with quote

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.
 
View user's profile Send private message Send e-mail
montego







PostPosted: Sun Jun 04, 2006 12:22 am Reply with quote

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







PostPosted: Sun Jun 04, 2006 2:12 am Reply with quote

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. Sad

Thanks for your help, if I find the answer I'll post it here.
 
Guardian2003







PostPosted: Sun Jun 04, 2006 2:21 am Reply with quote

jakec wrote:
I've emailed 1and1, but I'm still waiting for a reply. Sad

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







PostPosted: Sun Jun 04, 2006 7:23 am Reply with quote

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. Sad
 
Tao_Man







PostPosted: Mon Jun 05, 2006 1:24 pm Reply with quote

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







PostPosted: Mon Jun 05, 2006 2:45 pm Reply with quote

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







PostPosted: Mon Jun 05, 2006 4:29 pm Reply with quote

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







PostPosted: Tue Jun 06, 2006 9:19 am Reply with quote

Remove the phpinfo file though as soon as you can - you do not want to expose data like that to the world.
 
jakec







PostPosted: Tue Jun 06, 2006 11:02 am Reply with quote

No problem already done. Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©