Jump to content


Photo

CronJob & PHP


  • Please log in to reply
7 replies to this topic

#1 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 11 July 2006 - 07:02 AM

Hi,

i've got a script that writes a file to the server. if i run it from the webserver it works okay and writes the file to the server.

but if i run it as an cronjob with this command "php -f /var/www/tmi/output.php" it won't create a file on the server.

do i have to use a other command that the php script writes the file to the server?

best

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 11 July 2006 - 12:01 PM

yes, you can use a perl script instead.
PHP run with world permission (module). So unless you set the folder to world writable, It will not create any files.  Perl instead, running with server core, (i don't know whatever you called it), but it can write file anywhere. 
So yeah, if you're unconfortable to chmod your folder to 0777 (which is not recommended), you can use a perl script instead.
Life's too short for arguing.

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 01:40 PM

When you run PHP from a cron job, you can specify the user that the script runs under. Do that and your script will be able to write files with compromising the security of your system.

Ken

#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 11 July 2006 - 01:45 PM

My host use vdeck 2.0 and it did not have option to specify which user permission for php to run under.  Is there anyway of doing that within the script?

Life's too short for arguing.

#5 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 11 July 2006 - 01:54 PM

Hi,

i run the cronjob as user root so this user should have rights to write data to the server.

all the other stuff is done (read from database) but no file is created

best

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 12 July 2006 - 12:38 AM

Maybe the cron job should be run as www-data so it has server write access?
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 12 July 2006 - 12:45 PM

with user www-data there is also no wirting of the file :(

best

#8 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 12 July 2006 - 03:59 PM

Is there a way to specifiy the working directory for the cron job?
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users