[TYPO3-dev] HowTo: Running a cronscript using TYPO3 with CLI
Steffen Kamper
steffen at sk-typo3.de
Thu Jan 3 23:58:58 CET 2008
Hi Steffen,
it's very easy, here is a very very basic one
===============================
create BE user _cli_cronjob
in ext_localconf.php:
//register key for cli
$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['mycliscript']=
array('EXT:myext/croncli.php','_CLI_cronjob');
the croncli.php:
if (!defined('TYPO3_cliMode')) die('You cannot run this script directly!');
require_once(PATH_t3lib.'class.t3lib_cli.php');
class tx_myjobs extends t3lib_cli {
function main($argv) {
$args = $this->cli_getArgArray('-f',$argv);
print_r($args);
}
}
// Call the functionality
$myObj = t3lib_div::makeInstance('tx_myjobs');
$myObj->main($_SERVER["argv"]);
===============================
then call it on console:
/var/www/.../typo3/cli_dispatch.phpsh mycliscript -f hello
works.
vg Steffen
"Steffen Ritter" <info at rs-websystems.de> schrieb im Newsbeitrag
news:mailman.1.1199387764.1420.typo3-dev at lists.netfielders.de...
> Steffen Kamper schrieb:
>> "Ernesto Baschny [cron IT]" <ernst at cron-it.de> schrieb im Newsbeitrag
>> news:mailman.1.1199376508.29585.typo3-dev at lists.netfielders.de...
>>> Steffen Kamper wrote: on 03.01.2008 16:54:
>>>
>>>> So little additional question, how can I access commandline parameters?
>>>> e.g.
>>>> i want to start my script this way
>>>> /abspath/typo3/cli_dispatch.phpsh mysscript -f 100
>>> You pass $_SERVER['argv'] to your main() method of your class and it can
>>> handle the command line the way it wishes. AFAIK we don't have any
>>> getopt()-like functionality in TYPO3-core, so you have to do it your own
>>> way.
>>>
>>> Cheers,
>>> Ernesto
>>
>> I found something usable:
>> t3lib_cli::cli_getArgArray($option,$argv)
>>
>> i will test a bit with this and may be make a demo-ext, thx for your
>> hints.
>>
>> vg Steffen
> Fascinated by your discussion i tried the hole afternoon to create an own
> CLI Script using the cli_dispath.php.
> Against the information in
> typo3/sysext/lowlevel/HOWTO_clean_up_TYPO3_installations.txt it does not
> work as written in this Document. At the moment I'm going throug all files
> which are included while CLI and checking what happens.
> When finished I will report what I had to do, and publish some kind of
> "Howto"...
>
> mfG
>
> Steffen
>
More information about the TYPO3-dev
mailing list