HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   General (http://www.howtoforge.com/forums/forumdisplay.php?f=25)
-   -   cron job location (http://www.howtoforge.com/forums/showthread.php?t=46707)

Toucan 22nd June 2010 12:51

cron job location
 
I'm trying to run a script once a night that calls on some php files to update a billing status.

I've been trying to run this from the debian crontab but as the php files are stored /var/www/mydomain.com/web/billing/thephp.php cron fails to execute them are they are not stored in the same place as the where the cron job is executed from.

So my question is... in debian lenny, where does cron execute it's files from please?

David

Mark_NL 22nd June 2010 15:20

You can call that php file, but if you use relative includes etc in your php file, you need to chdir first ..

you could add
Code:

chdir("/var/www/mydomain.com/web/billing/");
at the start of your php file.

in your crontab you would put something like:

Code:

@daily www-data /usr/bin/php /var/www/mydomain.com/web/billing/thephp.php

Toucan 22nd June 2010 16:20

Thanks mark. I'd taken a slightly different approach and made this script which would call the php script.

#!/bin/bash
cd*./etc
/var/www/mydomain.com/web/billing/./statusupdate

when I'm back in front of a terminal I'll try your approach I think

thanks

Mark_NL 22nd June 2010 16:50

Yeah, you can also create a small bash script to chdir to the correct dir and then call the php script :) good luck!

Toucan 22nd June 2010 21:34

I went with your suggestion changing the php. Works a treat. Thanks!

BorderAmigos 22nd June 2010 23:55

Another suggestion is to use full path names for all commands and files so it will run the same regardless of where it's called from. No need to change directories that way.

(Better for me as on a complicated script I can forget what directory I'm in and start messing things up.)

Toucan 23rd June 2010 02:36

I see your point amigos. It was not my php script I was trying to get cron to run. It is part of an open source billing system called citrusdb.


All times are GMT +2. The time now is 16:02.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.