[TYPO3] Script run from cron job returns different result than when run from terminal

Peter Klein peter at umloud.dk
Fri Sep 12 11:21:22 CEST 2008


Hi Brian.

I had a similar problem with one of my cron scripts.

When you run it from the terminal/browser, you specify the full url
including the domain.
But when you run it as a true cron script, your script don't have the
domain name.

So usually you'll have to add the domain to all paths generated from
the cron script.

--
Peter Klein


On Fri, 12 Sep 2008 10:16:48 +0200, Brian Bendtsen <bb at bellevuevej.dk>
wrote:

>Hi
>
>Im working with the extension auxnewsmailer for sending newsletters 
>automatically and therefore I need to set up a cronjob.
>
>I have set up cronjobs before without any problems, but with this script 
>im having a bit of trouble.
>
>The script scans which news to send and sends them and when I run the 
>script from a terminal it works fine, but when its executed from the 
>cronjob it gives a different result. To give an example. When its run 
>correctly the script sends two newsletters to two accounts and the 
>newsletters look fine.
>
>When its run from the cronjob only one of the email accounts receive a 
>newsletter and the formatting is wrong.
>
>So, has it something to do with permissions. When I run the script from 
>terminal im logged in as root. But I have read its not a good idea to 
>run a cronjob as root.
>
>This is how the cronjob is set up:
>*/5 * * * * php <pathToScript>/mailer.sh > /dev/null/
>
>The script code:
>
>#!/usr/bin/php
><?php
>
>
>// set typo path to point to the root of the T3 installation - censored :)
>$typopath='***';
>
>// create a BE user called _cli_auxnewsmailer (must not be admin), for 
>better security change it to somethine else.
>$MCONF['name'] = '_CLI_auxnewsmailer';
>
>// *****************************************
>
>// Standard initialization of a CLI module:
>
>  // *****************************************
>
>
>if (@is_file($typopath.'typo3conf/ext/aux_newsmailer/mod1/index.php'))
>	$modulepath=$typopath.'typo3conf/ext/aux_newsmailer/';
>else
>	$modulepath=$typopath.'typo3/ext/aux_newsmailer/';
>
>// Defining circumstances for CLI mode:
>
>define('TYPO3_cliMode', TRUE);
>
>
>
>
>
>$BACK_PATH = '../../../../typo3/';
>define('TYPO3_mainDir', 'typo3/');
>define('PATH_thisScript',$typopath.'typo3/typo3');
>define('TYPO3_MOD_PATH', $modulepath.'/mailer/');
>// Include init file:
>require($typopath.'typo3/init.php');
>require($typopath.'typo3/sysext/lang/lang.php');
>
>$LANG=t3lib_div::makeInstance('language');
>$LANG->init('default');
>
>
>require($modulepath.'mod1/class_auxnewsmailer_core.php');
>
>
>$mailer=new tx_auxnewsmailer_core;
>$mailer->init();
>
>$mailer->batch($argv[1],'','');
>?>
>
>Any help is appreciated
>
>/Brian


More information about the TYPO3-english mailing list