jerry
Elixir standalone script in a Linux cron
Hello,
Is there a way I can write an elixir script and schedule it in a Linux cron job to perform some repetitive tasks?
I would like the script to invoke some Ecto functions from modules defined inside an Elixir mix project.
Any help would be most appreciated.
Thanks.
Jerry
Most Liked Responses
NobbZ
Your cron seems to want to start the application a second time, rather than to communicate with it, therefore ranch can’t boot, as the port it wants to listen on, is already in use by your main instance of the application.
If you use distillery just use a custom task, if you are using 1.9-releases, use their equivalent, if you use mix (as a command via cron) then make sure to use --no-start (IIRC), if you use an escript make sure it does not start the application and its dependencies, but just loads them.
NobbZ
Well, you need to start your ecto repository without the rest of the application.
Be aware that it might then crash as well, as dependencies for ecto might be missing.
To be honest, the easiest thing is probably to use quantum and trigger the task from within your application.
sweeneydavidj
Hi,
here is a nice article on using Elixir as a scripting language…
https://thoughtbot.com/blog/is-elixir-a-scripting-language
Enjoy ![]()








