# How to Run Logstash Immediately and Maintain a Scheduled Execution?

**URL:** <https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889>\
**Category:** Logstash\
**Created:** [January 30, 2025, 12:09pm UTC](https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889 "2025-01-30T12:09:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zikou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zikou/32/140193_2.png) [@Zikou](https://discuss.elastic.co/u/Zikou)\
**Post date:** [January 30, 2025, 12:09pm UTC](https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889/1 "2025-01-30T12:09:19Z")

</div>

I'm using Logstash to fetch data from a database and index it into Elasticsearch. My Logstash configuration includes a schedule to run every 50 minutes like this:

```auto
input {
  jdbc {
    jdbc_connection_string => "jdbc:mysql://your-database-url"
    jdbc_user => "your-user"
    jdbc_password => "your-password"
    schedule => "*/50 * * * *"
    statement => "SELECT * FROM your_table"
  }
}
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "my-index"
  }
}

```

What I Want to Achieve

- Delete the Elasticsearch index at 10:00 AM every day.
- Run Logstash immediately after the deletion.
- Ensure Logstash continues running on the 50-minute schedule.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [January 30, 2025, 1:00pm UTC](https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889/2 "2025-01-30T13:00:14Z")

</div>

Logstash does not work like that, it is built to keep running until stopped.

To do what you want you need to control the execution of Logstash outside of it, like using some bash scripts and crontab.

---

<div class="post-metadata">

**Author:** ![Zikou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zikou/32/140193_2.png) [@Zikou](https://discuss.elastic.co/u/Zikou)\
**Post date:** [January 30, 2025, 4:40pm UTC](https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889/3 "2025-01-30T16:40:05Z")

</div>

can you explain to me the schedule in logstash configuration for example  
/50 \* \* \* \* \*  
I want to know the starting point (is it when the logstash is started or 00:00)

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 30, 2025, 5:50pm UTC](https://discuss.elastic.co/t/how-to-run-logstash-immediately-and-maintain-a-scheduled-execution/373889/4 "2025-01-30T17:50:14Z")

</div>

If I run an exec plugin

```
exec { command => "/bin/true" schedule => "*/12 * * * *" }

```

then I get

```
[2025-01-30T12:41:34,777][INFO][logstash.agent] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
{
   "process" => {
       "exit_code" => 0,
    "command_line" => "/bin/true"
},
"@timestamp" => 2025-01-30T17:48:00.173038104Z,

```

so it looks like it starts at 00:00, not when logstash starts
