[TYPO3] Script run from cron job returns different result than when run from terminal
Brian Bendtsen
bb at bellevuevej.dk
Tue Sep 16 10:53:37 CEST 2008
Brian Bendtsen skrev:
> Peter Klein skrev:
>> On Fri, 12 Sep 2008 11:54:40 +0200, Brian Bendtsen <bb at bellevuevej.dk>
>> wrote:
>>
>>> Peter Klein skrev:
>>>> 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
>>> Hi Peter
>>>
>>> Could you show me, by changing a line or two in the attached script
>>> where you would insert the domain?
>>>
>>> /Brian
>>
>> No, unfortunatly there's no "quick fix" for it. :(
>>
>> You need to put in some debug code, so you can see if the various
>> paths is correct.
>> It could also be in the mod1/class_auxnewsmailer_core.php you are
>> using, where the domain is not set when used as a cron script.
>>
>> --
>> Peter
> ahh, now I understand, I will take a look at it.
>
> /Brian
So I spend a lot of time with this, debugging a lot and I see no
difference in paths or anything else between running the script from
terminal and as a cronjob. Im beginning to think its a server problem
and it has to do with the html formatted emails that are sent. If I only
sent text based emails there i no problem, but when its html mails a lot
is not delivered to the users. I dont have enough knowledge about unix
servers to solve this issue.
Does anyone have an idea what might be the problem?
The problem is, again:
1. activating script from backend or terminal to send an html formatted
email works fine.
2. running script from cronjob to send an html formatted email fails,
text emails are sent without any problems
/Brian
More information about the TYPO3-english
mailing list