# Run a long time-consuming task through commandline?

**URL:** <https://forum.getkirby.com/t/run-a-long-time-consuming-task-through-commandline/23236>\
**Category:** Questions\
**Tags:** v3\
**Created:** [August 26, 2021, 7:44pm UTC](https://forum.getkirby.com/t/run-a-long-time-consuming-task-through-commandline/23236 "2021-08-26T19:44:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![waffl](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@waffl](https://forum.getkirby.com/u/waffl)\
**Post date:** [August 26, 2021, 7:44pm UTC](https://forum.getkirby.com/t/run-a-long-time-consuming-task-through-commandline/23236/1 "2021-08-26T19:44:37Z")

</div>

I have a `multiselect` field like:

`Tags: Item A, Item B ...`

This field needs to be changed to a structured field to add more context like so:

```auto
Tags:
--
Note: Hello World
Tags: Item A
--
Note: Hi
Tags: Item B

```

Basically I thought to grab the collection of pages this needs to run on and use the `addToStructure` function as per [How to Programatically Add Entries to Structure Field - #3 by pedroborges](https://forum.getkirby.com/t/how-to-programatically-add-entries-to-structure-field/12607/3)

The problem is that this takes about 2-3s to execute per page, and there are thousands of pages which results in a very long execution time. Somewhat sloppily, I had my migration bound to a route in a plugin function and was trying to run it by curl’ing the endpoint with no timeout. I increased my PHP execution time to something massive like 90 minutes, but things still aren’t working properly (probably nginx issues in between).

In [Avoid Php script timeout](https://forum.getkirby.com/t/avoid-php-script-timeout/6304) @lukasbestle mentions running scripts in the commandline instead and was wondering how to best go about doing something like this?

As @bnomei was part of that conversation and is the author of [Kirby Janitor](https://github.com/bnomei/kirby3-janitor), have I answered my own question?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 26, 2021, 8:02pm UTC](https://forum.getkirby.com/t/run-a-long-time-consuming-task-through-commandline/23236/2 "2021-08-26T20:02:48Z")

</div>

To run a Kirby script from the command line, it’s easiest to copy the `index.php` file from the root of your Kirby site to another file (like `script.php`). Then you can replace the `render()` line with your code:

```php
<?php

require __DIR__. '/kirby/bootstrap.php';

$kirby = new Kirby();

// your custom code

```

You can run this script like this:

```php
php script.php

```

Make sure to delete the script again when you are done.

---

<div class="post-metadata">

**Author:** ![waffl](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@waffl](https://forum.getkirby.com/u/waffl)\
**Post date:** [August 29, 2021, 7:02pm UTC](https://forum.getkirby.com/t/run-a-long-time-consuming-task-through-commandline/23236/3 "2021-08-29T19:02:31Z")

</div>

Thank you for the response, I ended up doing this through a custom janitor job, using the backup script as an example to provide some more feedback/visibility of the progress via ‘climate’.
