# How can I run a Ruby script in a daily cronjob?

**URL:** https://meta.discourse.org/t/how-can-i-run-a-ruby-script-in-a-daily-cronjob/352129
**Category:** Development
**Created:** [February 13, 2025, 6:34pm UTC](https://meta.discourse.org/t/how-can-i-run-a-ruby-script-in-a-daily-cronjob/352129 "2025-02-13T18:34:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Xavier\_Garzon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xavier_garzon/32/485602_2.png) [@Xavier\_Garzon](https://meta.discourse.org/u/Xavier_Garzon)
#### Post date: [February 13, 2025, 6:34pm UTC](https://meta.discourse.org/t/how-can-i-run-a-ruby-script-in-a-daily-cronjob/352129/1 "2025-02-13T18:34:38Z")

</div>

I need to run a simple script daily with specific parameters like this. When I run it manually:

`bundle exec rails runner auto_send_messages_script.rb --messages-limit 3 --sleep-timer 5 --marker welcome_back_campaign_2025 --order-type created_at —-order desc`

I see no errors and everything is fine, I’m new to Ruby and wonder if there is an easy way to run this script and interact with Discourse.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 13, 2025, 7:35pm UTC](https://meta.discourse.org/t/how-can-i-run-a-ruby-script-in-a-daily-cronjob/352129/2 "2025-02-13T19:35:11Z")

</div>

The Discourse (and Rails) way of doing this would be to create a plugin and run it as a scheduled (sidekiq) Job.

There are loads of plugins with Jobs, have a look through them.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [February 13, 2025, 7:50pm UTC](https://meta.discourse.org/t/how-can-i-run-a-ruby-script-in-a-daily-cronjob/352129/3 "2025-02-13T19:50:20Z")

</div>

From an application-development point of view:

> [@merefield](#):
>
> The Discourse (and Rails) way of doing this would be to create a plugin and run it as a scheduled (sidekiq) Job.

💯

From a systems point of view:

Easiest thing to do is run it on the host.

> [@Launcher run app gives error when trying backup](https://meta.discourse.org/t/launcher-run-app-gives-error-when-trying-backup/346553/5):
>
> You have a scheduler outside of the container available, right? You can schedule it there, e.g.: # put in host crontab # run backup once every 4 hours on the hour 0 \*/4 \* \* \* docker exec app discourse backup --sql-only
